1
+ /*
2
+ * Copyright 1999-2023 Alibaba Group Holding Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ package com .alibaba .nacos .client .auth .ram .utils ;
18
+
19
+ import com .alibaba .nacos .api .PropertyKeyConst ;
20
+ import com .alibaba .nacos .client .auth .ram .identify .CredentialService ;
21
+ import com .alibaba .nacos .client .auth .ram .identify .Credentials ;
22
+ import org .junit .jupiter .api .AfterEach ;
23
+ import org .junit .jupiter .api .BeforeEach ;
24
+ import org .junit .jupiter .api .Test ;
25
+
26
+ import java .util .Properties ;
27
+
28
+ import static org .junit .jupiter .api .Assertions .assertEquals ;
29
+ import static org .junit .jupiter .api .Assertions .assertNull ;
30
+
31
+ public class RamUtilTest {
32
+
33
+ private Properties properties ;
34
+
35
+ @ BeforeEach
36
+ public void setUp () throws Exception {
37
+ SpasAdapter .freeCredentialInstance ();
38
+ Credentials credentials = new Credentials ("spasAk" , "spasSk" , "spasNamespaceId" );
39
+ CredentialService .getInstance ().setStaticCredential (credentials );
40
+ properties = new Properties ();
41
+ properties .setProperty (PropertyKeyConst .ACCESS_KEY , "userAk" );
42
+ properties .setProperty (PropertyKeyConst .SECRET_KEY , "userSk" );
43
+ }
44
+
45
+ @ AfterEach
46
+ public void tearDown () throws Exception {
47
+ SpasAdapter .freeCredentialInstance ();
48
+ }
49
+
50
+ @ Test
51
+ public void testGetAccessKeyWithUserAkSk () {
52
+ assertEquals ("userAk" , RamUtil .getAccessKey (properties ));
53
+ assertEquals ("userSk" , RamUtil .getSecretKey (properties ));
54
+ }
55
+
56
+ @ Test
57
+ public void testGetAccessKeyWithSpasAkSk () {
58
+ assertEquals ("spasAk" , RamUtil .getAccessKey (new Properties ()));
59
+ assertEquals ("spasSk" , RamUtil .getSecretKey (new Properties ()));
60
+ }
61
+
62
+ @ Test
63
+ public void testGetAccessKeyWithoutSpasAkSk () {
64
+ Properties properties1 = new Properties ();
65
+ properties1 .setProperty (PropertyKeyConst .IS_USE_RAM_INFO_PARSING , "false" );
66
+ assertNull (RamUtil .getAccessKey (properties1 ));
67
+ assertNull (RamUtil .getSecretKey (properties1 ));
68
+ }
69
+ }
0 commit comments