2
2
// Licensed under the MIT license.
3
3
4
4
import * as sinon from "sinon" ;
5
- import { AppConfigurationClient } from "@azure/app-configuration" ;
5
+ import { AppConfigurationClient , ConfigurationSetting } from "@azure/app-configuration" ;
6
6
import { ClientSecretCredential } from "@azure/identity" ;
7
7
import { KeyVaultSecret , SecretClient } from "@azure/keyvault-secrets" ;
8
8
import * as uuid from "uuid" ;
@@ -11,17 +11,26 @@ const TEST_CLIENT_ID = "00000000-0000-0000-0000-000000000000";
11
11
const TEST_TENANT_ID = "00000000-0000-0000-0000-000000000000" ;
12
12
const TEST_CLIENT_SECRET = "0000000000000000000000000000000000000000" ;
13
13
14
- function mockAppConfigurationClientListConfigurationSettings ( kvList : any [ ] ) {
14
+ function mockAppConfigurationClientListConfigurationSettings ( kvList : ConfigurationSetting [ ] ) {
15
15
function * testKvSetGnerator ( kvs : any [ ] ) {
16
16
yield * kvs ;
17
17
}
18
18
sinon . stub ( AppConfigurationClient . prototype , "listConfigurationSettings" ) . callsFake ( ( listOptions ) => {
19
19
const keyFilter = listOptions ?. keyFilter ?? "*" ;
20
20
const labelFilter = listOptions ?. labelFilter ?? "*" ;
21
21
const kvs = kvList . filter ( kv => {
22
- const keyMatched = keyFilter . endsWith ( "*" ) ? kv . key . startsWith ( keyFilter . slice ( 0 , keyFilter . length - 1 ) ) : kv . key === keyFilter ;
23
- const labelMatched = labelFilter . endsWith ( "*" ) ? kv . label . startsWith ( labelFilter . slice ( 0 , labelFilter . length - 1 ) )
24
- : ( labelFilter === "\0" ? kv . label === null : kv . label === labelFilter ) ; // '\0' in labelFilter, null in config setting.
22
+ const keyMatched = keyFilter . endsWith ( "*" ) ? kv . key . startsWith ( keyFilter . slice ( 0 , - 1 ) ) : kv . key === keyFilter ;
23
+
24
+ let labelMatched = false ;
25
+ if ( labelFilter === "*" ) {
26
+ labelMatched = true ;
27
+ } else if ( labelFilter === "\0" ) {
28
+ labelMatched = kv . label === undefined ;
29
+ } else if ( labelFilter . endsWith ( "*" ) ) {
30
+ labelMatched = kv . label !== undefined && kv . label . startsWith ( labelFilter . slice ( 0 , - 1 ) ) ;
31
+ } else {
32
+ labelMatched = kv . label === labelFilter ;
33
+ }
25
34
return keyMatched && labelMatched ;
26
35
} )
27
36
return testKvSetGnerator ( kvs ) as any ;
@@ -64,36 +73,33 @@ const createMockedTokenCredential = (tenantId = TEST_TENANT_ID, clientId = TEST_
64
73
return new ClientSecretCredential ( tenantId , clientId , clientSecret ) ;
65
74
}
66
75
67
- const createMockedKeyVaultReference = ( key : string , vaultUri : string ) => ( {
76
+ const createMockedKeyVaultReference = ( key : string , vaultUri : string ) : ConfigurationSetting => ( {
68
77
// https://${vaultName}.vault.azure.net/secrets/${secretName}
69
78
value : `{"uri":"${ vaultUri } "}` ,
70
79
key,
71
- label : null ,
72
80
contentType : "application/vnd.microsoft.appconfig.keyvaultref+json;charset=utf-8" ,
73
- lastModified : "2023-05-09T08:51:11.000Z" ,
81
+ lastModified : new Date ( ) ,
74
82
tags : {
75
83
} ,
76
84
etag : "SPJSMnJ2ph4BAjftWfdIctV2VIyQxtcIzRbh1oxTBkM" ,
77
85
isReadOnly : false ,
78
86
} ) ;
79
87
80
- const createMockedJsonKeyValue = ( key : string , value : any ) => ( {
88
+ const createMockedJsonKeyValue = ( key : string , value : any ) : ConfigurationSetting => ( {
81
89
value : value ,
82
90
key : key ,
83
- label : null ,
84
91
contentType : "application/json" ,
85
- lastModified : "2023-05-04T04:32:56.000Z" ,
92
+ lastModified : new Date ( ) ,
86
93
tags : { } ,
87
94
etag : "GdmsLWq3mFjFodVEXUYRmvFr3l_qRiKAW_KdpFbxZKk" ,
88
95
isReadOnly : false
89
96
} ) ;
90
97
91
- const createMockedKeyValue = ( props : { [ key : string ] : any } ) => ( Object . assign ( {
98
+ const createMockedKeyValue = ( props : { [ key : string ] : any } ) : ConfigurationSetting => ( Object . assign ( {
92
99
value : "TestValue" ,
93
100
key : "TestKey" ,
94
- label : null ,
95
101
contentType : "" ,
96
- lastModified : new Date ( ) . toISOString ( ) ,
102
+ lastModified : new Date ( ) ,
97
103
tags : { } ,
98
104
etag : uuid . v4 ( ) ,
99
105
isReadOnly : false
0 commit comments