@@ -18,6 +18,7 @@ package azure
18
18
19
19
import (
20
20
"encoding/json"
21
+ "fmt"
21
22
"strconv"
22
23
"strings"
23
24
"sync"
@@ -170,6 +171,55 @@ func TestAzureTokenSource(t *testing.T) {
170
171
expectedConfigModes := []string {"1" , "0" }
171
172
172
173
for i , configMode := range configModes {
174
+ t .Run (fmt .Sprintf ("validate token from cfg with configMode %v" , configMode ), func (t * testing.T ) {
175
+ const (
176
+ serverID = "fakeServerID"
177
+ clientID = "fakeClientID"
178
+ tenantID = "fakeTenantID"
179
+ accessToken = "fakeToken"
180
+ environment = "fakeEnvironment"
181
+ refreshToken = "fakeToken"
182
+ expiresIn = "foo"
183
+ expiresOn = "foo"
184
+ )
185
+ cfg := map [string ]string {
186
+ cfgConfigMode : string (configMode ),
187
+ cfgApiserverID : serverID ,
188
+ cfgClientID : clientID ,
189
+ cfgTenantID : tenantID ,
190
+ cfgEnvironment : environment ,
191
+ cfgAccessToken : accessToken ,
192
+ cfgRefreshToken : refreshToken ,
193
+ cfgExpiresIn : expiresIn ,
194
+ cfgExpiresOn : expiresOn ,
195
+ }
196
+ fakeSource := fakeTokenSource {}
197
+ persiter := & fakePersister {cache : make (map [string ]string )}
198
+ tokenCache := newAzureTokenCache ()
199
+ tokenSource := newAzureTokenSource (& fakeSource , tokenCache , cfg , configMode , persiter )
200
+ azTokenSource := tokenSource .(* azureTokenSource )
201
+ token , err := azTokenSource .retrieveTokenFromCfg ()
202
+ if err != nil {
203
+ t .Errorf ("failed to retrieve the token form cfg: %s" , err )
204
+ }
205
+ if token .apiserverID != serverID {
206
+ t .Errorf ("expecting token.apiserverID: %s, actual: %s" , serverID , token .apiserverID )
207
+ }
208
+ if token .clientID != clientID {
209
+ t .Errorf ("expecting token.clientID: %s, actual: %s" , clientID , token .clientID )
210
+ }
211
+ if token .tenantID != tenantID {
212
+ t .Errorf ("expecting token.tenantID: %s, actual: %s" , tenantID , token .tenantID )
213
+ }
214
+ expectedAudience := serverID
215
+ if configMode == configModeDefault {
216
+ expectedAudience = fmt .Sprintf ("spn:%s" , serverID )
217
+ }
218
+ if token .token .Resource != expectedAudience {
219
+ t .Errorf ("expecting adal token.Resource: %s, actual: %s" , expectedAudience , token .token .Resource )
220
+ }
221
+ })
222
+
173
223
t .Run ("validate token against cache" , func (t * testing.T ) {
174
224
fakeAccessToken := "fake token 1"
175
225
fakeSource := fakeTokenSource {
0 commit comments