1
+ /*
2
+ * AET
3
+ *
4
+ * Copyright (C) 2013 Cognifide Limited
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
7
+ * in compliance with the License. You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
12
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13
+ * or implied. See the License for the specific language governing permissions and limitations under
14
+ * the License.
15
+ */
16
+ package com .cognifide .aet .job .common .modifiers .login ;
17
+
18
+ import static com .cognifide .aet .job .common .modifiers .login .LoginModifierConfig .DEFAULT_LOGIN ;
19
+ import static com .cognifide .aet .job .common .modifiers .login .LoginModifierConfig .DEFAULT_PASSWORD ;
20
+ import static com .cognifide .aet .job .common .modifiers .login .LoginModifierConfig .LOGIN_PAGE_PARAM ;
21
+ import static com .cognifide .aet .job .common .modifiers .login .LoginModifierConfig .LOGIN_PARAM ;
22
+ import static com .cognifide .aet .job .common .modifiers .login .LoginModifierConfig .PASSWORD_PARAM ;
23
+ import static org .junit .Assert .assertEquals ;
24
+
25
+ import com .cognifide .aet .job .api .exceptions .ParametersException ;
26
+ import com .googlecode .zohhak .api .TestWith ;
27
+ import com .googlecode .zohhak .api .runners .ZohhakRunner ;
28
+ import java .util .HashMap ;
29
+ import java .util .Map ;
30
+ import org .junit .Rule ;
31
+ import org .junit .Test ;
32
+ import org .junit .contrib .java .lang .system .EnvironmentVariables ;
33
+ import org .junit .runner .RunWith ;
34
+
35
+ @ RunWith (ZohhakRunner .class )
36
+ public class LoginModifierConfigTest {
37
+
38
+ @ Rule
39
+ public final EnvironmentVariables environmentVariables = new EnvironmentVariables ();
40
+
41
+ @ Test
42
+ public void whenNoPasswordProvided_expectDefaultPasswordInTheConfig () throws ParametersException {
43
+ Map <String , String > params = new HashMap <>();
44
+ params .put (LOGIN_PAGE_PARAM , "whatever" );
45
+
46
+ LoginModifierConfig tested = new LoginModifierConfig (params );
47
+
48
+ assertEquals (DEFAULT_PASSWORD , tested .getPassword ());
49
+ }
50
+
51
+ @ TestWith ({
52
+ "s3cret" ,
53
+ "$ecret" ,
54
+ "${ecret" ,
55
+ "$ecret}" ,
56
+ "s3cret}"
57
+ })
58
+ public void whenPasswordPassedAsPlainText_expectPasswordInTheConfig (String password ) throws ParametersException {
59
+ Map <String , String > params = new HashMap <>();
60
+ params .put (LOGIN_PAGE_PARAM , "whatever" );
61
+ params .put (PASSWORD_PARAM , password );
62
+
63
+ LoginModifierConfig tested = new LoginModifierConfig (params );
64
+
65
+ assertEquals (password , tested .getPassword ());
66
+ }
67
+
68
+ @ Test
69
+ public void whenPasswordPassedAsEnv_expectPasswordInTheConfig () throws ParametersException {
70
+ Map <String , String > params = new HashMap <>();
71
+ params .put (LOGIN_PAGE_PARAM , "whatever" );
72
+ params .put (PASSWORD_PARAM , "${MY_SECRET_PASSWORD}" );
73
+ environmentVariables .set ("MY_SECRET_PASSWORD" , "pass-form-env" );
74
+
75
+ LoginModifierConfig tested = new LoginModifierConfig (params );
76
+
77
+ assertEquals ("pass-form-env" , tested .getPassword ());
78
+ }
79
+
80
+ @ Test
81
+ public void whenPasswordPassedAsEnvAndEnvNotSet_expectDefaultPasswordInTheConfig () throws ParametersException {
82
+ Map <String , String > params = new HashMap <>();
83
+ params .put (LOGIN_PAGE_PARAM , "whatever" );
84
+ params .put (PASSWORD_PARAM , "${MY_SECRET_PASSWORD}" );
85
+
86
+ LoginModifierConfig tested = new LoginModifierConfig (params );
87
+
88
+ assertEquals (DEFAULT_PASSWORD , tested .getPassword ());
89
+ }
90
+
91
+ //-----
92
+
93
+ @ Test
94
+ public void whenNoLoginProvided_expectDefaultLoginInTheConfig () throws ParametersException {
95
+ Map <String , String > params = new HashMap <>();
96
+ params .put (LOGIN_PAGE_PARAM , "whatever" );
97
+
98
+ LoginModifierConfig tested = new LoginModifierConfig (params );
99
+
100
+ assertEquals (DEFAULT_LOGIN , tested .getLogin ());
101
+ }
102
+
103
+ @ TestWith ({
104
+ "s3cret" ,
105
+ "$ecret" ,
106
+ "${ecret" ,
107
+ "$ecret}" ,
108
+ "s3cret}"
109
+ })
110
+ public void whenLoginPassedAsPlainText_expectLoginInTheConfig (String login ) throws ParametersException {
111
+ Map <String , String > params = new HashMap <>();
112
+ params .put (LOGIN_PAGE_PARAM , "whatever" );
113
+ params .put (LOGIN_PARAM , login );
114
+
115
+ LoginModifierConfig tested = new LoginModifierConfig (params );
116
+
117
+ assertEquals (login , tested .getLogin ());
118
+ }
119
+
120
+ @ Test
121
+ public void whenLoginPassedAsEnv_expectLoginInTheConfig () throws ParametersException {
122
+ Map <String , String > params = new HashMap <>();
123
+ params .put (LOGIN_PAGE_PARAM , "whatever" );
124
+ params .put (LOGIN_PARAM , "${MY_SECRET_LOGIN}" );
125
+ environmentVariables .set ("MY_SECRET_LOGIN" , "user-form-env" );
126
+
127
+ LoginModifierConfig tested = new LoginModifierConfig (params );
128
+
129
+ assertEquals ("user-form-env" , tested .getLogin ());
130
+ }
131
+
132
+ @ Test
133
+ public void whenLoginPassedAsEnvAndEnvNotSet_expectDefaultLoginInTheConfig () throws ParametersException {
134
+ Map <String , String > params = new HashMap <>();
135
+ params .put (LOGIN_PAGE_PARAM , "whatever" );
136
+ params .put (DEFAULT_LOGIN , "${MY_SECRET_PASSWORD}" );
137
+
138
+ LoginModifierConfig tested = new LoginModifierConfig (params );
139
+
140
+ assertEquals (DEFAULT_LOGIN , tested .getLogin ());
141
+ }
142
+
143
+ }
0 commit comments