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

Function TestCheckClientIsAuthorizedForAPI

internal/cli/utils_shared_test.go:54–137  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

52}
53
54func TestCheckClientIsAuthorizedForAPI(t *testing.T) {
55 const audience = "https://cli-demo.us.auth0.com/api/v2/"
56
57 client := &management.Client{
58 ClientID: auth0.String("some-client-id"),
59 Name: auth0.String("some-client-name"),
60 }
61
62 tests := []struct {
63 name string
64 organization string
65 grantList *management.ClientGrantList
66 apiError error
67 expectedError string
68 }{
69 {
70 name: "no grant exists",
71 organization: "",
72 grantList: &management.ClientGrantList{},
73 expectedError: "the some-client-name application is not authorized to request access tokens for this API " +
74 audience,
75 },
76 {
77 name: "api error",
78 organization: "",
79 apiError: errors.New("unexpected error"),
80 expectedError: "failed to find client grants for API identifier " +
81 "\"" + audience + "\" and client ID \"some-client-id\": unexpected error",
82 },
83 {
84 name: "grant exists, no org required",
85 organization: "",
86 grantList: &management.ClientGrantList{
87 ClientGrants: []*management.ClientGrant{
88 {OrganizationUsage: auth0.String("allow")},
89 },
90 },
91 },
92 {
93 name: "grant requires org, org provided",
94 organization: "org_abc123",
95 grantList: &management.ClientGrantList{
96 ClientGrants: []*management.ClientGrant{
97 {OrganizationUsage: auth0.String("require")},
98 },
99 },
100 },
101 {
102 name: "grant requires org, no org provided",
103 organization: "",
104 grantList: &management.ClientGrantList{
105 ClientGrants: []*management.ClientGrant{
106 {OrganizationUsage: auth0.String("require")},
107 },
108 },
109 expectedError: "the client grant for " + audience + " requires an organization.\n\n" +
110 "Use the --organization flag to specify one",
111 },

Callers

nothing calls this directly

Calls 4

EXPECTMethod · 0.95
NewMockClientGrantAPIFunction · 0.92
ListMethod · 0.65

Tested by

no test coverage detected