MCPcopy Create free account
hub / github.com/auth0/auth0-cli / TestAPICmd_IsInsufficientScopeError

Function TestAPICmd_IsInsufficientScopeError

internal/cli/api_test.go:104–173  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

102}
103
104func TestAPICmd_IsInsufficientScopeError(t *testing.T) {
105 var testCases = []struct {
106 name string
107 inputStatusCode int
108 inputResponseBody string
109 expectedError string
110 }{
111 {
112 name: "it does not detect 404 error",
113 inputStatusCode: 404,
114 inputResponseBody: `{
115 "statusCode": 404,
116 "error": "Not Found",
117 "message": "Not Found"
118 }`,
119 expectedError: "",
120 },
121 {
122 name: "it does not detect a 200 HTTP response",
123 inputStatusCode: 200,
124 inputResponseBody: `{
125 "allowed_logout_urls": [],
126 "change_password": {
127 "enabled": true,
128 "html": "<html>LOL</html>"
129 },
130 "default_audience": "",
131 }`,
132 expectedError: "",
133 },
134 {
135 name: "it correctly detects an insufficient scope error",
136 inputStatusCode: 403,
137 inputResponseBody: `{
138 "statusCode": 403,
139 "error": "Forbidden",
140 "message": "Insufficient scope, expected any of: create:client_grants",
141 "errorCode": "insufficient_scope"
142 }`,
143 expectedError: "request failed because access token lacks scope: create:client_grants.\n If authenticated via client credentials, add this scope to the designated client. If authenticated as a user, request this scope during login by running `auth0 login --scopes create:client_grants`",
144 },
145 {
146 name: "it correctly detects an insufficient scope error with multiple scope",
147 inputStatusCode: 403,
148 inputResponseBody: `{
149 "statusCode": 403,
150 "error": "Forbidden",
151 "message": "Insufficient scope, expected any of: read:clients, read:client_summary",
152 "errorCode": "insufficient_scope"
153 }`,
154 expectedError: "request failed because access token lacks scope: read:clients.\n If authenticated via client credentials, add this scope to the designated client. If authenticated as a user, request this scope during login by running `auth0 login --scopes read:clients`",
155 },
156 }
157
158 for _, testCase := range testCases {
159 t.Run(testCase.name, func(t *testing.T) {
160 input := http.Response{
161 Body: io.NopCloser(bytes.NewReader([]byte(testCase.inputResponseBody))),

Callers

nothing calls this directly

Calls 1

isInsufficientScopeErrorFunction · 0.85

Tested by

no test coverage detected