Debian Codegraph @

apps/internal/oauth/ops/authority/authority_test.go

raw symbols SCIP
1 // Copyright (c) Microsoft Corporation.
2 // Licensed under the MIT license.
3
4 package authorityscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/
5
6 import (
7 "contextscip-go gomod github.com/golang/go/src go1.18 context/"
8 "encoding/jsonscip-go gomod github.com/golang/go/src go1.18 `encoding/json`/"
9 "errorsscip-go gomod github.com/golang/go/src go1.18 errors/"
10 "fmtscip-go gomod github.com/golang/go/src go1.18 fmt/"
11 "net/httpscip-go gomod github.com/golang/go/src go1.18 `net/http`/"
12 "net/urlscip-go gomod github.com/golang/go/src go1.18 `net/url`/"
13 "reflectscip-go gomod github.com/golang/go/src go1.18 reflect/"
14 "stringsscip-go gomod github.com/golang/go/src go1.18 strings/"
15 "testingscip-go gomod github.com/golang/go/src go1.18 testing/"
16
17 "github.com/kylelemons/godebug/prettyscip-go gomod github.com/kylelemons/godebug v1.1.0 `github.com/kylelemons/godebug/pretty`/"
18 )
19
20 type fakeJSONCallerscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/fakeJSONCaller# struct {
21 errscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/fakeJSONCaller#err. bool
22
23 respscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/fakeJSONCaller#resp. []byte
24
25 gotEndpointscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/fakeJSONCaller#gotEndpoint. string
26 gotHeadersscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/fakeJSONCaller#gotHeaders. httpscip-go gomod github.com/golang/go/src go1.18 `net/http`/.Headerscip-go gomod github.com/golang/go/src go1.18 `net/http`/Header#
27 gotQVscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/fakeJSONCaller#gotQV. urlscip-go gomod github.com/golang/go/src go1.18 `net/url`/.Valuesscip-go gomod github.com/golang/go/src go1.18 `net/url`/Values#
28 gotBodyscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/fakeJSONCaller#gotBody. interface{}
29 gotRespscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/fakeJSONCaller#gotResp. interface{}
30 }
31
32 func (f *fakeJSONCallerscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/fakeJSONCaller#) JSONCallscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/fakeJSONCaller#JSONCall().(ctx contextscip-go gomod github.com/golang/go/src go1.18 context/.Contextscip-go gomod github.com/golang/go/src go1.18 context/Context#, endpoint string, headers httpscip-go gomod github.com/golang/go/src go1.18 `net/http`/.Headerscip-go gomod github.com/golang/go/src go1.18 `net/http`/Header#, qv urlscip-go gomod github.com/golang/go/src go1.18 `net/url`/.Valuesscip-go gomod github.com/golang/go/src go1.18 `net/url`/Values#, body, resp interface{}) error {
33 if f.errscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/fakeJSONCaller#err. {
34 return errorsscip-go gomod github.com/golang/go/src go1.18 errors/.Newscip-go gomod github.com/golang/go/src go1.18 errors/New().("error")
35 }
36 f.gotEndpointscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/fakeJSONCaller#gotEndpoint. = endpoint
37 f.gotHeadersscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/fakeJSONCaller#gotHeaders. = headers
38 f.gotQVscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/fakeJSONCaller#gotQV. = qv
39 f.gotBodyscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/fakeJSONCaller#gotBody. = body
40 f.gotRespscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/fakeJSONCaller#gotResp. = resp
41
42 if f.respscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/fakeJSONCaller#resp. != nil {
43 if err := jsonscip-go gomod github.com/golang/go/src go1.18 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.18 `encoding/json`/Unmarshal().(f.respscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/fakeJSONCaller#resp., resp); err != nil {
44 return err
45 }
46 }
47
48 return nil
49 }
50
51 func (f *fakeJSONCallerscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/fakeJSONCaller#) comparescip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/fakeJSONCaller#compare().(endpoint string, headers httpscip-go gomod github.com/golang/go/src go1.18 `net/http`/.Headerscip-go gomod github.com/golang/go/src go1.18 `net/http`/Header#, qv urlscip-go gomod github.com/golang/go/src go1.18 `net/url`/.Valuesscip-go gomod github.com/golang/go/src go1.18 `net/url`/Values#, body, resp interface{}) error {
52 if f.gotEndpointscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/fakeJSONCaller#gotEndpoint. != endpoint {
53 return fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.18 fmt/Errorf().("got endpoint == %s, want endpoint == %s", f.gotEndpointscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/fakeJSONCaller#gotEndpoint., endpoint)
54 }
55 if diff := prettyscip-go gomod github.com/kylelemons/godebug v1.1.0 `github.com/kylelemons/godebug/pretty`/.Comparescip-go gomod github.com/kylelemons/godebug v1.1.0 `github.com/kylelemons/godebug/pretty`/Compare().(headers, f.gotHeadersscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/fakeJSONCaller#gotHeaders.); diff != "" {
56 return fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.18 fmt/Errorf().("headers -want/+got:\n%s", diff)
57 }
58 if diff := prettyscip-go gomod github.com/kylelemons/godebug v1.1.0 `github.com/kylelemons/godebug/pretty`/.Comparescip-go gomod github.com/kylelemons/godebug v1.1.0 `github.com/kylelemons/godebug/pretty`/Compare().(qv, f.gotQVscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/fakeJSONCaller#gotQV.); diff != "" {
59 return fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.18 fmt/Errorf().("qv -want/+got:\n%s", diff)
60 }
61 if diff := prettyscip-go gomod github.com/kylelemons/godebug v1.1.0 `github.com/kylelemons/godebug/pretty`/.Comparescip-go gomod github.com/kylelemons/godebug v1.1.0 `github.com/kylelemons/godebug/pretty`/Compare().(body, f.gotBodyscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/fakeJSONCaller#gotBody.); diff != "" {
62 return fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.18 fmt/Errorf().("body -want/+got:\n%s", diff)
63 }
64 gotValue := reflectscip-go gomod github.com/golang/go/src go1.18 reflect/.ValueOfscip-go gomod github.com/golang/go/src go1.18 reflect/ValueOf().(f.gotRespscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/fakeJSONCaller#gotResp.)
65 if gotValue.Kindscip-go gomod github.com/golang/go/src go1.18 reflect/Value#Kind().() != reflectscip-go gomod github.com/golang/go/src go1.18 reflect/.Ptrscip-go gomod github.com/golang/go/src go1.18 reflect/Ptr. {
66 return fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.18 fmt/Errorf().("resp cannot be a non-pointer type")
67 }
68 gotValue = gotValue.Elemscip-go gomod github.com/golang/go/src go1.18 reflect/Value#Elem().()
69
70 gotName := gotValue.Typescip-go gomod github.com/golang/go/src go1.18 reflect/Value#Type().().Namescip-go gomod github.com/golang/go/src go1.18 reflect/Type#Name().()
71 wantName := reflectscip-go gomod github.com/golang/go/src go1.18 reflect/.ValueOfscip-go gomod github.com/golang/go/src go1.18 reflect/ValueOf().(resp).Elemscip-go gomod github.com/golang/go/src go1.18 reflect/Value#Elem().().Typescip-go gomod github.com/golang/go/src go1.18 reflect/Value#Type().().Namescip-go gomod github.com/golang/go/src go1.18 reflect/Type#Name().()
72
73 if gotName != wantName {
74 return fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.18 fmt/Errorf().("resp type was %s, want %s", gotName, wantName)
75 }
76 return nil
77 }
78
79 var testAuthorityEndpointsscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/testAuthorityEndpoints. = NewEndpointsscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/NewEndpoints().(
80 "https://login.microsoftonline.com/v2.0/authorize",
81 "https://login.microsoftonline.com/v2.0/token",
82 "https://login.microsoftonline.com/v2.0",
83 "login.microsoftonline.com",
84 )
85
86 func TestUserRealmscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/TestUserRealm().(t *testingscip-go gomod github.com/golang/go/src go1.18 testing/.Tscip-go gomod github.com/golang/go/src go1.18 testing/T#) {
87 authParams := AuthParamsscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/AuthParams#{
88 Usernamescip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/AuthParams#Username.: "username",
89 Endpointsscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/AuthParams#Endpoints.: testAuthorityEndpointsscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/testAuthorityEndpoints.,
90 CorrelationIDscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/AuthParams#CorrelationID.: "id",
91 }
92
93 tests := []struct {
94 desc string
95 err bool
96 endpoint string
97 jsonResp *UserRealmscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/UserRealm#
98 headers httpscip-go gomod github.com/golang/go/src go1.18 `net/http`/.Headerscip-go gomod github.com/golang/go/src go1.18 `net/http`/Header#
99 qv urlscip-go gomod github.com/golang/go/src go1.18 `net/url`/.Valuesscip-go gomod github.com/golang/go/src go1.18 `net/url`/Values#
100 resp interface{}
101 }{
102 {
103 desc: "Error: comm returns error",
104 err: true,
105 },
106 {
107 desc: "Success",
108 endpoint: fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.18 fmt/Sprintf().("https://login.microsoftonline.com/common/UserRealm/%s", urlscip-go gomod github.com/golang/go/src go1.18 `net/url`/.PathEscapescip-go gomod github.com/golang/go/src go1.18 `net/url`/PathEscape().(authParams.Usernamescip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/AuthParams#Username.)),
109 headers: httpscip-go gomod github.com/golang/go/src go1.18 `net/http`/.Headerscip-go gomod github.com/golang/go/src go1.18 `net/http`/Header#{
110 "client-request-id": []string{"id"},
111 },
112 qv: urlscip-go gomod github.com/golang/go/src go1.18 `net/url`/.Valuesscip-go gomod github.com/golang/go/src go1.18 `net/url`/Values#{
113 "api-version": []string{"1.0"},
114 },
115 jsonResp: &UserRealmscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/UserRealm#{
116 AccountTypescip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/UserRealm#AccountType.: "Managed",
117 DomainNamescip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/UserRealm#DomainName.: "microsoftonline.com",
118 CloudInstanceNamescip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/UserRealm#CloudInstanceName.: "instance",
119 CloudAudienceURNscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/UserRealm#CloudAudienceURN.: "urn",
120 },
121 resp: &UserRealmscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/UserRealm#{},
122 },
123 }
124
125 for _, test := range tests {
126 fake := &fakeJSONCallerscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/fakeJSONCaller#{errscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/fakeJSONCaller#err.: test.err}
127 client := Clientscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/Client#{fake}
128 if test.jsonResp != nil {
129 b, err := jsonscip-go gomod github.com/golang/go/src go1.18 `encoding/json`/.Marshalscip-go gomod github.com/golang/go/src go1.18 `encoding/json`/Marshal().(test.jsonResp)
130 if err != nil {
131 panic(err)
132 }
133 fake.respscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/fakeJSONCaller#resp. = b
134 }
135
136 // We don't care about the result, that is just a translation from the JSON handled
137 // automatically in the comm package. We care only that the comm package got what
138 // it needed.
139 _, err := client.UserRealmscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/Client#UserRealm().(contextscip-go gomod github.com/golang/go/src go1.18 context/.Backgroundscip-go gomod github.com/golang/go/src go1.18 context/Background().(), authParams)
140 switch {
141 case err == nil && test.err:
142 t.Errorfscip-go gomod github.com/golang/go/src go1.18 testing/common#Errorf().("TestUserRealm(%s): got err == nil , want err != nil", test.desc)
143 continue
144 case err != nil && !test.err:
145 t.Errorfscip-go gomod github.com/golang/go/src go1.18 testing/common#Errorf().("TestUserRealm(%s): got err == %s , want err == nil", test.desc, err)
146 continue
147 case err != nil:
148 continue
149 }
150
151 if err := fake.comparescip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/fakeJSONCaller#compare().(test.endpoint, test.headers, test.qv, nil, test.resp); err != nil {
152 t.Errorfscip-go gomod github.com/golang/go/src go1.18 testing/common#Errorf().("TestUserRealm(%s): %s", test.desc, err)
153 }
154 }
155 }
156
157 func TestTenantDiscoveryResponsescip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/TestTenantDiscoveryResponse().(t *testingscip-go gomod github.com/golang/go/src go1.18 testing/.Tscip-go gomod github.com/golang/go/src go1.18 testing/T#) {
158 tests := []struct {
159 desc string
160 err bool
161 endpoint string
162 resp interface{}
163 }{
164 {
165 desc: "Error: comm returns error",
166 err: true,
167 },
168 {
169 desc: "Success",
170 endpoint: "endpoint",
171 resp: &TenantDiscoveryResponsescip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/TenantDiscoveryResponse#{},
172 },
173 }
174
175 for _, test := range tests {
176 fake := &fakeJSONCallerscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/fakeJSONCaller#{errscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/fakeJSONCaller#err.: test.err}
177 client := Clientscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/Client#{fake}
178
179 // We don't care about the result, that is just a translation from the JSON handled
180 // automatically in the comm package. We care only that the comm package got what
181 // it needed.
182 _, err := client.GetTenantDiscoveryResponsescip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/Client#GetTenantDiscoveryResponse().(contextscip-go gomod github.com/golang/go/src go1.18 context/.Backgroundscip-go gomod github.com/golang/go/src go1.18 context/Background().(), "endpoint")
183 switch {
184 case err == nil && test.err:
185 t.Errorfscip-go gomod github.com/golang/go/src go1.18 testing/common#Errorf().("TestTenantDiscoveryResponse(%s): got err == nil , want err != nil", test.desc)
186 continue
187 case err != nil && !test.err:
188 t.Errorfscip-go gomod github.com/golang/go/src go1.18 testing/common#Errorf().("TestTenantDiscoveryResponse(%s): got err == %s , want err == nil", test.desc, err)
189 continue
190 case err != nil:
191 continue
192 }
193
194 if err := fake.comparescip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/fakeJSONCaller#compare().(test.endpoint, httpscip-go gomod github.com/golang/go/src go1.18 `net/http`/.Headerscip-go gomod github.com/golang/go/src go1.18 `net/http`/Header#{}, nil, nil, test.resp); err != nil {
195 t.Errorfscip-go gomod github.com/golang/go/src go1.18 testing/common#Errorf().("TestTenantDiscoveryResponse(%s): %s", test.desc, err)
196 }
197 }
198 }
199
200 func TestAADInstanceDiscoveryscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/TestAADInstanceDiscovery().(t *testingscip-go gomod github.com/golang/go/src go1.18 testing/.Tscip-go gomod github.com/golang/go/src go1.18 testing/T#) {
201 tests := []struct {
202 desc string
203 err bool
204 authInfo Infoscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/Info#
205 endpoint string
206 qv urlscip-go gomod github.com/golang/go/src go1.18 `net/url`/.Valuesscip-go gomod github.com/golang/go/src go1.18 `net/url`/Values#
207 resp interface{}
208 }{
209 {
210 desc: "Error: comm returns error",
211 err: true,
212 },
213 {
214 desc: "Success with authorityInfo.Host not in trusted list",
215 endpoint: fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.18 fmt/Sprintf().(instanceDiscoveryEndpointscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/instanceDiscoveryEndpoint., defaultHostscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/defaultHost.),
216 authInfo: Infoscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/Info#{
217 Hostscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/Info#Host.: "host",
218 Tenantscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/Info#Tenant.: "tenant",
219 },
220 qv: urlscip-go gomod github.com/golang/go/src go1.18 `net/url`/.Valuesscip-go gomod github.com/golang/go/src go1.18 `net/url`/Values#{
221 "api-version": []string{"1.1"},
222 "authorization_endpoint": []string{fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.18 fmt/Sprintf().(authorizationEndpointscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/authorizationEndpoint., "host", "tenant")},
223 },
224 resp: &InstanceDiscoveryResponsescip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/InstanceDiscoveryResponse#{},
225 },
226 {
227 desc: "Success with authorityInfo.Host in trusted list",
228 endpoint: fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.18 fmt/Sprintf().(instanceDiscoveryEndpointscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/instanceDiscoveryEndpoint., "login.microsoftonline.de"),
229 authInfo: Infoscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/Info#{
230 Hostscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/Info#Host.: "login.microsoftonline.de",
231 Tenantscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/Info#Tenant.: "tenant",
232 },
233 qv: urlscip-go gomod github.com/golang/go/src go1.18 `net/url`/.Valuesscip-go gomod github.com/golang/go/src go1.18 `net/url`/Values#{
234 "api-version": []string{"1.1"},
235 "authorization_endpoint": []string{fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.18 fmt/Sprintf().(authorizationEndpointscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/authorizationEndpoint., "login.microsoftonline.de", "tenant")},
236 },
237 resp: &InstanceDiscoveryResponsescip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/InstanceDiscoveryResponse#{},
238 },
239 }
240
241 for _, test := range tests {
242 fake := &fakeJSONCallerscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/fakeJSONCaller#{errscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/fakeJSONCaller#err.: test.err}
243 client := Clientscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/Client#{fake}
244
245 // We don't care about the result, that is just a translation from the JSON handled
246 // automatically in the comm package. We care only that the comm package got what
247 // it needed.
248 _, err := client.AADInstanceDiscoveryscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/Client#AADInstanceDiscovery().(contextscip-go gomod github.com/golang/go/src go1.18 context/.Backgroundscip-go gomod github.com/golang/go/src go1.18 context/Background().(), test.authInfo)
249 switch {
250 case err == nil && test.err:
251 t.Errorfscip-go gomod github.com/golang/go/src go1.18 testing/common#Errorf().("AADInstanceDiscovery(%s): got err == nil , want err != nil", test.desc)
252 continue
253 case err != nil && !test.err:
254 t.Errorfscip-go gomod github.com/golang/go/src go1.18 testing/common#Errorf().("AADInstanceDiscovery(%s): got err == %s , want err == nil", test.desc, err)
255 continue
256 case err != nil:
257 continue
258 }
259
260 if err := fake.comparescip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/fakeJSONCaller#compare().(test.endpoint, httpscip-go gomod github.com/golang/go/src go1.18 `net/http`/.Headerscip-go gomod github.com/golang/go/src go1.18 `net/http`/Header#{}, test.qv, nil, test.resp); err != nil {
261 t.Errorfscip-go gomod github.com/golang/go/src go1.18 testing/common#Errorf().("AADInstanceDiscovery(%s): %s", test.desc, err)
262 }
263 }
264 }
265
266 func TestAADInstanceDiscoveryWithRegionscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/TestAADInstanceDiscoveryWithRegion().(t *testingscip-go gomod github.com/golang/go/src go1.18 testing/.Tscip-go gomod github.com/golang/go/src go1.18 testing/T#) {
267 client := Clientscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/Client#{&fakeJSONCallerscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/fakeJSONCaller#{}}
268 region := "region"
269 discoveryPath := "tenant/v2.0/.well-known/openid-configuration"
270 publicCloudEndpoint := fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.18 fmt/Sprintf().("https://%s.login.microsoft.com/%s", region, discoveryPath)
271 for _, test := range []struct{ host, expectedEndpoint string }{
272 {"login.chinacloudapi.cn", fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.18 fmt/Sprintf().("https://%s.login.chinacloudapi.cn/%s", region, discoveryPath)},
273 {"login.microsoft.com", publicCloudEndpoint},
274 {"login.microsoftonline.com", publicCloudEndpoint},
275 {"login.windows.net", publicCloudEndpoint},
276 {"login.windows-ppe.net", fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.18 fmt/Sprintf().("https://%s.login.windows-ppe.net/%s", region, discoveryPath)},
277 {"sts.windows.net", publicCloudEndpoint},
278 } {
279 t.Runscip-go gomod github.com/golang/go/src go1.18 testing/T#Run().(test.host, func(t *testingscip-go gomod github.com/golang/go/src go1.18 testing/.Tscip-go gomod github.com/golang/go/src go1.18 testing/T#) {
280 authInfo := Infoscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/Info#{Hostscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/Info#Host.: test.host, Tenantscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/Info#Tenant.: "tenant", Regionscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/Info#Region.: region}
281 resp, err := client.AADInstanceDiscoveryscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/Client#AADInstanceDiscovery().(contextscip-go gomod github.com/golang/go/src go1.18 context/.Backgroundscip-go gomod github.com/golang/go/src go1.18 context/Background().(), authInfo)
282 if err != nil {
283 t.Errorfscip-go gomod github.com/golang/go/src go1.18 testing/common#Errorf().("AADInstanceDiscoveryWithRegion failing with %s", err)
284 }
285 expectedPreferredNetwork := fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.18 fmt/Sprintf().("%v.%v", region, test.host)
286 expectedPreferredCache := test.host
287 if resp.TenantDiscoveryEndpointscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/InstanceDiscoveryResponse#TenantDiscoveryEndpoint. != test.expectedEndpoint {
288 t.Errorfscip-go gomod github.com/golang/go/src go1.18 testing/common#Errorf().("AADInstanceDiscoveryWithRegion incorrect TenantDiscoveryEndpoint: got: %s, want: %s", resp.TenantDiscoveryEndpointscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/InstanceDiscoveryResponse#TenantDiscoveryEndpoint., test.expectedEndpoint)
289 }
290 if resp.Metadatascip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/InstanceDiscoveryResponse#Metadata.[0].PreferredNetworkscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/InstanceDiscoveryMetadata#PreferredNetwork. != expectedPreferredNetwork {
291 t.Errorfscip-go gomod github.com/golang/go/src go1.18 testing/common#Errorf().("AADInstanceDiscoveryWithRegion incorrect Preferred Network got: %s, want: %s", resp.Metadatascip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/InstanceDiscoveryResponse#Metadata.[0].PreferredNetworkscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/InstanceDiscoveryMetadata#PreferredNetwork., expectedPreferredNetwork)
292 }
293 if resp.Metadatascip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/InstanceDiscoveryResponse#Metadata.[0].PreferredCachescip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/InstanceDiscoveryMetadata#PreferredCache. != expectedPreferredCache {
294 t.Errorfscip-go gomod github.com/golang/go/src go1.18 testing/common#Errorf().("AADInstanceDiscoveryWithRegion incorrect Preferred Cache got: %s, want: %s", resp.Metadatascip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/InstanceDiscoveryResponse#Metadata.[0].PreferredCachescip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/InstanceDiscoveryMetadata#PreferredCache., expectedPreferredCache)
295
296 }
297 })
298 }
299 }
300
301 func TestCreateAuthorityInfoFromAuthorityUriscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/TestCreateAuthorityInfoFromAuthorityUri().(t *testingscip-go gomod github.com/golang/go/src go1.18 testing/.Tscip-go gomod github.com/golang/go/src go1.18 testing/T#) {
302 const authorityURI = "https://login.microsoftonline.com/common/"
303
304 want := Infoscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/Info#{
305 Hostscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/Info#Host.: "login.microsoftonline.com",
306 CanonicalAuthorityURIscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/Info#CanonicalAuthorityURI.: authorityURI,
307 AuthorityTypescip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/Info#AuthorityType.: "MSSTS",
308 UserRealmURIPrefixscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/Info#UserRealmURIPrefix.: "https://login.microsoftonline.com/common/userrealm/",
309 Tenantscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/Info#Tenant.: "common",
310 ValidateAuthorityscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/Info#ValidateAuthority.: true,
311 }
312 got, err := NewInfoFromAuthorityURIscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/NewInfoFromAuthorityURI().(authorityURI, true, false)
313 if err != nil {
314 t.Fatalfscip-go gomod github.com/golang/go/src go1.18 testing/common#Fatalf().("TestCreateAuthorityInfoFromAuthorityUri: got err == %s, want err == nil", err)
315 }
316
317 if diff := prettyscip-go gomod github.com/kylelemons/godebug v1.1.0 `github.com/kylelemons/godebug/pretty`/.Comparescip-go gomod github.com/kylelemons/godebug v1.1.0 `github.com/kylelemons/godebug/pretty`/Compare().(want, got); diff != "" {
318 t.Errorfscip-go gomod github.com/golang/go/src go1.18 testing/common#Errorf().("TestCreateAuthorityInfoFromAuthorityUri: -want/+got:\n%s", diff)
319 }
320 }
321
322 func TestAuthParamsWithTenantscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/TestAuthParamsWithTenant().(t *testingscip-go gomod github.com/golang/go/src go1.18 testing/.Tscip-go gomod github.com/golang/go/src go1.18 testing/T#) {
323 uuid1 := "00000000-0000-0000-0000-000000000000"
324 uuid2 := stringsscip-go gomod github.com/golang/go/src go1.18 strings/.ReplaceAllscip-go gomod github.com/golang/go/src go1.18 strings/ReplaceAll().(uuid1, "0", "1")
325 host := "https://localhost/"
326 for _, test := range []struct {
327 authority, expectedAuthority, tenant string
328 expectError bool
329 }{
330 {authority: host + "common", tenant: uuid1, expectedAuthority: host + uuid1},
331 {authority: host + "organizations", tenant: uuid1, expectedAuthority: host + uuid1},
332 {authority: host + uuid1, tenant: uuid2, expectedAuthority: host + uuid2},
333 {authority: host + uuid1, tenant: "common", expectError: true},
334 {authority: host + uuid1, tenant: "organizations", expectError: true},
335 {authority: host + "adfs", tenant: uuid1, expectError: true},
336 {authority: host + "consumers", tenant: uuid1, expectError: true},
337 } {
338 t.Runscip-go gomod github.com/golang/go/src go1.18 testing/T#Run().("", func(t *testingscip-go gomod github.com/golang/go/src go1.18 testing/.Tscip-go gomod github.com/golang/go/src go1.18 testing/T#) {
339 info, err := NewInfoFromAuthorityURIscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/NewInfoFromAuthorityURI().(test.authority, false, false)
340 if err != nil {
341 t.Fatalscip-go gomod github.com/golang/go/src go1.18 testing/common#Fatal().(err)
342 }
343 params := NewAuthParamsscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/NewAuthParams().("client-id", info)
344 p, err := params.WithTenantscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/AuthParams#WithTenant().(test.tenant)
345 if test.expectError {
346 if err == nil {
347 t.Fatalscip-go gomod github.com/golang/go/src go1.18 testing/common#Fatal().("expected an error")
348 }
349 return
350 }
351 if err != nil {
352 t.Fatalscip-go gomod github.com/golang/go/src go1.18 testing/common#Fatal().(err)
353 }
354
355 if v := stringsscip-go gomod github.com/golang/go/src go1.18 strings/.TrimSuffixscip-go gomod github.com/golang/go/src go1.18 strings/TrimSuffix().(p.AuthorityInfoscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/AuthParams#AuthorityInfo..CanonicalAuthorityURIscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/Info#CanonicalAuthorityURI., "/"); v != test.expectedAuthority {
356 t.Fatalfscip-go gomod github.com/golang/go/src go1.18 testing/common#Fatalf().(`unexpected tenant "%s"`, v)
357 }
358 })
359 }
360
361 // WithTenant shouldn't change AuthorityInfo fields unrelated to the tenant, such as Region
362 t.Runscip-go gomod github.com/golang/go/src go1.18 testing/T#Run().("AuthorityInfo", func(t *testingscip-go gomod github.com/golang/go/src go1.18 testing/.Tscip-go gomod github.com/golang/go/src go1.18 testing/T#) {
363 a := "A"
364 b := "B"
365 before, err := NewInfoFromAuthorityURIscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/NewInfoFromAuthorityURI().("https://localhost/"+a, true, false)
366 if err != nil {
367 t.Fatalscip-go gomod github.com/golang/go/src go1.18 testing/common#Fatal().(err)
368 }
369 before.Regionscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/Info#Region. = "region"
370 params := NewAuthParamsscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/NewAuthParams().("client-id", before)
371 p, err := params.WithTenantscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/AuthParams#WithTenant().(b)
372 if err != nil {
373 t.Fatalscip-go gomod github.com/golang/go/src go1.18 testing/common#Fatal().(err)
374 }
375 after := p.AuthorityInfoscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/AuthParams#AuthorityInfo.
376
377 // these values should be different because they contain the tenant (this is tested above)
378 after.CanonicalAuthorityURIscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/Info#CanonicalAuthorityURI. = before.CanonicalAuthorityURIscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/Info#CanonicalAuthorityURI.
379 after.Tenantscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/Info#Tenant. = before.Tenantscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/Info#Tenant.
380 // With those fields equal, we can compare the before and after Infos without enumerating
381 // their fields i.e., we can implicitly compare all the other fields at once. With this
382 // approach, when Info gets a new field, this test needs an update only if that field
383 // contains the tenant, in which case this test will break so maintainers don't overlook it.
384 if diff := prettyscip-go gomod github.com/kylelemons/godebug v1.1.0 `github.com/kylelemons/godebug/pretty`/.Comparescip-go gomod github.com/kylelemons/godebug v1.1.0 `github.com/kylelemons/godebug/pretty`/Compare().(before, after); diff != "" {
385 t.Fatalscip-go gomod github.com/golang/go/src go1.18 testing/common#Fatal().(diff)
386 }
387 })
388 }
389
390 func TestMergeCapabilitiesAndClaimsscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/TestMergeCapabilitiesAndClaims().(t *testingscip-go gomod github.com/golang/go/src go1.18 testing/.Tscip-go gomod github.com/golang/go/src go1.18 testing/T#) {
391 for _, test := range []struct {
392 capabilities []string
393 challenge, desc, expected string
394 err bool
395 }{
396 {
397 desc: "no capabilities or challenge",
398 expected: "",
399 },
400 {
401 desc: "encoded challenge",
402 capabilities: []string{"cp1"},
403 challenge: "eyJpZF90b2tlbiI6eyJhdXRoX3RpbWUiOnsiZXNzZW50aWFsIjp0cnVlfX19",
404 err: true,
405 },
406 {
407 desc: "only capabilities",
408 capabilities: []string{"cp1"},
409 expected: `{"access_token":{"xms_cc":{"values":["cp1"]}}}`,
410 },
411 {
412 desc: "only challenge",
413 challenge: `{"id_token":{"auth_time":{"essential":true}}}`,
414 expected: `{"id_token":{"auth_time":{"essential":true}}}`,
415 },
416 {
417 desc: "overlapping claim", // i.e. capabilities and claims are siblings
418 capabilities: []string{"cp1", "cp2"},
419 challenge: `{"access_token":{"nbf":{"essential":true, "value":"42"}}}`,
420 expected: `{"access_token":{"nbf":{"essential":true, "value":"42"}, "xms_cc":{"values":["cp1","cp2"]}}}`,
421 },
422 {
423 desc: "non-overlapping claim",
424 capabilities: []string{"cp1", "cp2"},
425 challenge: `{"id_token":{"auth_time":{"essential":true}}}`,
426 expected: `{"id_token":{"auth_time":{"essential":true}}, "access_token":{"xms_cc":{"values":["cp1","cp2"]}}}`,
427 },
428 {
429 desc: "overlapping and non-overlapping claims",
430 capabilities: []string{"cp1", "cp2"},
431 challenge: `{"id_token":{"auth_time":{"essential":true}},"access_token":{"nbf":{"essential":true, "value":"42"}}}`,
432 expected: `{"id_token":{"auth_time":{"essential":true}},"access_token":{"nbf":{"essential":true, "value":"42"},"xms_cc":{"values":["cp1","cp2"]}}}`,
433 },
434 } {
435 cpb, err := NewClientCapabilitiesscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/NewClientCapabilities().(test.capabilities)
436 if err != nil {
437 t.Fatalscip-go gomod github.com/golang/go/src go1.18 testing/common#Fatal().(err)
438 }
439 ap := AuthParamsscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/AuthParams#{Capabilitiesscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/AuthParams#Capabilities.: cpb, Claimsscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/AuthParams#Claims.: test.challenge}
440 t.Runscip-go gomod github.com/golang/go/src go1.18 testing/T#Run().(test.desc, func(t *testingscip-go gomod github.com/golang/go/src go1.18 testing/.Tscip-go gomod github.com/golang/go/src go1.18 testing/T#) {
441 var expected map[string]any
442 if err := jsonscip-go gomod github.com/golang/go/src go1.18 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.18 `encoding/json`/Unmarshal().([]byte(test.expected), &expected); err != nil && test.expected != "" {
443 t.Fatalscip-go gomod github.com/golang/go/src go1.18 testing/common#Fatal().("test bug: the expected result must be JSON or an empty string")
444 }
445 merged, err := ap.MergeCapabilitiesAndClaimsscip-go gomod github.com/AzureAD/microsoft-authentication-library-for-go . `github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority`/AuthParams#MergeCapabilitiesAndClaims().()
446 if err != nil {
447 if test.err {
448 return
449 }
450 t.Fatalscip-go gomod github.com/golang/go/src go1.18 testing/common#Fatal().(err)
451 }
452 if merged == test.expected {
453 return
454 }
455 var actual map[string]any
456 if err = jsonscip-go gomod github.com/golang/go/src go1.18 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.18 `encoding/json`/Unmarshal().([]byte(merged), &actual); err != nil {
457 t.Fatalscip-go gomod github.com/golang/go/src go1.18 testing/common#Fatal().(err)
458 }
459 if diff := prettyscip-go gomod github.com/kylelemons/godebug v1.1.0 `github.com/kylelemons/godebug/pretty`/.Comparescip-go gomod github.com/kylelemons/godebug v1.1.0 `github.com/kylelemons/godebug/pretty`/Compare().(expected, actual); diff != "" {
460 t.Fatalscip-go gomod github.com/golang/go/src go1.18 testing/common#Fatal().(diff)
461 }
462 })
463 }
464 }