| 1 | package console |
| 2 | |
| 3 | import ( |
| 4 | "errors" |
| 5 | "testing" |
| 6 | |
| 7 | "github.com/aws/smithy-go" |
| 8 | ) |
| 9 | |
| 10 | // TestIsAuthShapedError pins the classifier the review round added: |
| 11 | // realCECosts must latch (permanently disable itself for the process) only |
| 12 | // on the "billing IAM isn't set up here" shape — AccessDenied and an |
| 13 | // unrecognized/invalid credential — and must NOT latch on a throttle, a |
| 14 | // service-side limit, a 5xx, or a plain non-API error, all of which are |
| 15 | // worth retrying on the next hourly tick. |
| 16 | func TestIsAuthShapedError(t *testing.T) { |
| 17 | cases := []struct { |
| 18 | name string |
| 19 | err error |
| 20 | want bool |
| 21 | }{ |
| 22 | {"access denied exception", &smithy.GenericAPIError{Code: "AccessDeniedException"}, true}, |
| 23 | {"access denied bare", &smithy.GenericAPIError{Code: "AccessDenied"}, true}, |
| 24 | {"unrecognized client", &smithy.GenericAPIError{Code: "UnrecognizedClientException"}, true}, |
| 25 | {"invalid client token id", &smithy.GenericAPIError{Code: "InvalidClientTokenId"}, true}, |
| 26 | {"invalid access key id", &smithy.GenericAPIError{Code: "InvalidAccessKeyId"}, true}, |
| 27 | {"expired token", &smithy.GenericAPIError{Code: "ExpiredTokenException"}, true}, |
| 28 | {"auth failure", &smithy.GenericAPIError{Code: "AuthFailure"}, true}, |
| 29 | {"throttling", &smithy.GenericAPIError{Code: "ThrottlingException"}, false}, |
| 30 | {"limit exceeded", &smithy.GenericAPIError{Code: "LimitExceededException"}, false}, |
| 31 | {"internal error", &smithy.GenericAPIError{Code: "InternalError"}, false}, |
| 32 | {"service unavailable", &smithy.GenericAPIError{Code: "ServiceUnavailableException"}, false}, |
| 33 | {"plain error", errors.New("network is down"), false}, |
| 34 | {"nil", nil, false}, |
| 35 | } |
| 36 | for _, c := range cases { |
| 37 | if got := isAuthShapedError(c.err); got != c.want { |
| 38 | t.Errorf("%s: isAuthShapedError(%v) = %v, want %v", c.name, c.err, got, c.want) |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | |