Skip to content

Commit

Permalink
AuthManager constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
adutra committed Dec 19, 2024
1 parent 52f4423 commit 2a3f4af
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public static AuthManager loadAuthManager(String name, Map<String, String> prope
DynConstructors.builder(AuthManager.class)
.loader(AuthManagers.class.getClassLoader())
.impl(impl, String.class) // with name
.impl(impl) // without name
.buildChecked();
} catch (NoSuchMethodException e) {
throw new IllegalArgumentException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
/** An auth manager that adds static BASIC authentication data to outgoing HTTP requests. */
public final class BasicAuthManager implements AuthManager {

public BasicAuthManager(String ignored) {
// no-op
}

@Override
public AuthSession catalogSession(RESTClient sharedClient, Map<String, String> properties) {
Preconditions.checkArgument(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
/** An auth manager that does not add any authentication data to outgoing HTTP requests. */
public class NoopAuthManager implements AuthManager {

public NoopAuthManager(String ignored) {
// no-op
}

@Override
public AuthSession catalogSession(RESTClient sharedClient, Map<String, String> properties) {
return AuthSession.EMPTY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class TestBasicAuthManager {

@Test
void missingUsername() {
try (AuthManager authManager = new BasicAuthManager()) {
try (AuthManager authManager = new BasicAuthManager("test")) {
assertThatThrownBy(() -> authManager.catalogSession(null, Map.of()))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage(
Expand All @@ -39,7 +39,7 @@ void missingUsername() {

@Test
void missingPassword() {
try (AuthManager authManager = new BasicAuthManager()) {
try (AuthManager authManager = new BasicAuthManager("test")) {
Map<String, String> properties = Map.of(AuthProperties.BASIC_USERNAME, "alice");
assertThatThrownBy(() -> authManager.catalogSession(null, properties))
.isInstanceOf(IllegalArgumentException.class)
Expand All @@ -52,7 +52,7 @@ void missingPassword() {
void success() {
Map<String, String> properties =
Map.of(AuthProperties.BASIC_USERNAME, "alice", AuthProperties.BASIC_PASSWORD, "secret");
try (AuthManager authManager = new BasicAuthManager();
try (AuthManager authManager = new BasicAuthManager("test");
AuthSession session = authManager.catalogSession(null, properties)) {
assertThat(session)
.isEqualTo(
Expand Down

0 comments on commit 2a3f4af

Please sign in to comment.