-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(#1089): kubernetes client config with auth token
- Allow configuration with new oauthToken - Add restrictions to allow config only with oauthToken or username and password - Update Tests - Update Documentation
- Loading branch information
Showing
15 changed files
with
406 additions
and
75 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
48 changes: 48 additions & 0 deletions
48
...s-kubernetes/src/main/java/org/citrusframework/kubernetes/config/CredentialValidator.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,48 @@ | ||
/* | ||
* Copyright 2024 the original author or authors. | ||
* | ||
* 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 org.citrusframework.kubernetes.config; | ||
|
||
import static org.citrusframework.util.StringUtils.hasText; | ||
import static org.citrusframework.util.StringUtils.isEmpty; | ||
|
||
public class CredentialValidator { | ||
|
||
public CredentialValidator() { | ||
throw new IllegalArgumentException("Utility class shall not be instantiated!"); | ||
} | ||
|
||
/** | ||
* Validates the given credentials based on the following rules. Returns {@code true} if and only if none of the | ||
* following conditions are met: | ||
* <ul> | ||
* <li>{@code username} is set AND {@code oauthToken} is set</li> | ||
* <li>{@code password} is set AND {@code oauthToken} is set</li> | ||
* <li>{@code username} is <b>not</b> set AND {@code password} is set</li> | ||
* </ul> | ||
* All other combinations are valid. | ||
* | ||
* @param username The username. | ||
* @param password The password. | ||
* @param oauthToken The OAuth token. | ||
* @return true if the combination is valid, false otherwise. | ||
*/ | ||
public static boolean isValid(String username, String password, String oauthToken) { | ||
return (!hasText(username) || !hasText(oauthToken)) | ||
&& (!hasText(password) || !hasText(oauthToken)) | ||
&& (!isEmpty(username) || !hasText(password)); | ||
} | ||
} |
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
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
29 changes: 29 additions & 0 deletions
29
...bernetes/src/test/java/org/citrusframework/kubernetes/config/CredentialValidatorTest.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,29 @@ | ||
package org.citrusframework.kubernetes.config; | ||
|
||
import org.testng.annotations.DataProvider; | ||
import org.testng.annotations.Test; | ||
|
||
import static org.testng.Assert.assertEquals; | ||
|
||
public class CredentialValidatorTest { | ||
|
||
private static final String IS_VALID_DATA_PROVIDER = "is-valid"; | ||
|
||
@DataProvider(name = IS_VALID_DATA_PROVIDER) | ||
public static Object[][] primeNumbers() { | ||
return new Object[][]{ | ||
{"user1", "pass1", null, true}, | ||
{null, null, "token1", true}, | ||
{"user1", null, "token1", false}, | ||
{null, "pass1", "token1", false}, | ||
{"user1", "pass1", "token1", false}, | ||
{null, "pass1", null, false}, | ||
{null, null, null, true} | ||
}; | ||
} | ||
|
||
@Test(dataProvider = IS_VALID_DATA_PROVIDER) | ||
public void isValid(String username, String password, String oauthToken, boolean expectedResult) { | ||
assertEquals(CredentialValidator.isValid(username, password, oauthToken), expectedResult); | ||
} | ||
} |
Oops, something went wrong.