-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes #512, login modifier reads from env
- Loading branch information
1 parent
d11cd37
commit 36ac96e
Showing
5 changed files
with
205 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
143 changes: 143 additions & 0 deletions
143
...s/src/test/java/com/cognifide/aet/job/common/modifiers/login/LoginModifierConfigTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
/* | ||
* AET | ||
* | ||
* Copyright (C) 2013 Cognifide Limited | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package com.cognifide.aet.job.common.modifiers.login; | ||
|
||
import static com.cognifide.aet.job.common.modifiers.login.LoginModifierConfig.DEFAULT_LOGIN; | ||
import static com.cognifide.aet.job.common.modifiers.login.LoginModifierConfig.DEFAULT_PASSWORD; | ||
import static com.cognifide.aet.job.common.modifiers.login.LoginModifierConfig.LOGIN_PAGE_PARAM; | ||
import static com.cognifide.aet.job.common.modifiers.login.LoginModifierConfig.LOGIN_PARAM; | ||
import static com.cognifide.aet.job.common.modifiers.login.LoginModifierConfig.PASSWORD_PARAM; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
import com.cognifide.aet.job.api.exceptions.ParametersException; | ||
import com.googlecode.zohhak.api.TestWith; | ||
import com.googlecode.zohhak.api.runners.ZohhakRunner; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.contrib.java.lang.system.EnvironmentVariables; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(ZohhakRunner.class) | ||
public class LoginModifierConfigTest { | ||
|
||
@Rule | ||
public final EnvironmentVariables environmentVariables = new EnvironmentVariables(); | ||
|
||
@Test | ||
public void whenNoPasswordProvided_expectDefaultPasswordInTheConfig() throws ParametersException { | ||
Map<String, String> params = new HashMap<>(); | ||
params.put(LOGIN_PAGE_PARAM, "whatever"); | ||
|
||
LoginModifierConfig tested = new LoginModifierConfig(params); | ||
|
||
assertEquals(DEFAULT_PASSWORD, tested.getPassword()); | ||
} | ||
|
||
@TestWith({ | ||
"s3cret", | ||
"$ecret", | ||
"${ecret", | ||
"$ecret}", | ||
"s3cret}" | ||
}) | ||
public void whenPasswordPassedAsPlainText_expectPasswordInTheConfig(String password) throws ParametersException { | ||
Map<String, String> params = new HashMap<>(); | ||
params.put(LOGIN_PAGE_PARAM, "whatever"); | ||
params.put(PASSWORD_PARAM, password); | ||
|
||
LoginModifierConfig tested = new LoginModifierConfig(params); | ||
|
||
assertEquals(password, tested.getPassword()); | ||
} | ||
|
||
@Test | ||
public void whenPasswordPassedAsEnv_expectPasswordInTheConfig() throws ParametersException { | ||
Map<String, String> params = new HashMap<>(); | ||
params.put(LOGIN_PAGE_PARAM, "whatever"); | ||
params.put(PASSWORD_PARAM, "${MY_SECRET_PASSWORD}"); | ||
environmentVariables.set("MY_SECRET_PASSWORD", "pass-form-env"); | ||
|
||
LoginModifierConfig tested = new LoginModifierConfig(params); | ||
|
||
assertEquals("pass-form-env", tested.getPassword()); | ||
} | ||
|
||
@Test | ||
public void whenPasswordPassedAsEnvAndEnvNotSet_expectDefaultPasswordInTheConfig() throws ParametersException { | ||
Map<String, String> params = new HashMap<>(); | ||
params.put(LOGIN_PAGE_PARAM, "whatever"); | ||
params.put(PASSWORD_PARAM, "${MY_SECRET_PASSWORD}"); | ||
|
||
LoginModifierConfig tested = new LoginModifierConfig(params); | ||
|
||
assertEquals(DEFAULT_PASSWORD, tested.getPassword()); | ||
} | ||
|
||
//----- | ||
|
||
@Test | ||
public void whenNoLoginProvided_expectDefaultLoginInTheConfig() throws ParametersException { | ||
Map<String, String> params = new HashMap<>(); | ||
params.put(LOGIN_PAGE_PARAM, "whatever"); | ||
|
||
LoginModifierConfig tested = new LoginModifierConfig(params); | ||
|
||
assertEquals(DEFAULT_LOGIN, tested.getLogin()); | ||
} | ||
|
||
@TestWith({ | ||
"s3cret", | ||
"$ecret", | ||
"${ecret", | ||
"$ecret}", | ||
"s3cret}" | ||
}) | ||
public void whenLoginPassedAsPlainText_expectLoginInTheConfig(String login) throws ParametersException { | ||
Map<String, String> params = new HashMap<>(); | ||
params.put(LOGIN_PAGE_PARAM, "whatever"); | ||
params.put(LOGIN_PARAM, login); | ||
|
||
LoginModifierConfig tested = new LoginModifierConfig(params); | ||
|
||
assertEquals(login, tested.getLogin()); | ||
} | ||
|
||
@Test | ||
public void whenLoginPassedAsEnv_expectLoginInTheConfig() throws ParametersException { | ||
Map<String, String> params = new HashMap<>(); | ||
params.put(LOGIN_PAGE_PARAM, "whatever"); | ||
params.put(LOGIN_PARAM, "${MY_SECRET_LOGIN}"); | ||
environmentVariables.set("MY_SECRET_LOGIN", "user-form-env"); | ||
|
||
LoginModifierConfig tested = new LoginModifierConfig(params); | ||
|
||
assertEquals("user-form-env", tested.getLogin()); | ||
} | ||
|
||
@Test | ||
public void whenLoginPassedAsEnvAndEnvNotSet_expectDefaultLoginInTheConfig() throws ParametersException { | ||
Map<String, String> params = new HashMap<>(); | ||
params.put(LOGIN_PAGE_PARAM, "whatever"); | ||
params.put(DEFAULT_LOGIN, "${MY_SECRET_PASSWORD}"); | ||
|
||
LoginModifierConfig tested = new LoginModifierConfig(params); | ||
|
||
assertEquals(DEFAULT_LOGIN, tested.getLogin()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters