Skip to content

Commit

Permalink
Add tests for obo authenticator for rerequest and type
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Liang <jiallian@amazon.com>
  • Loading branch information
RyanL1997 committed Oct 9, 2023
1 parent 7bf71ba commit 027cd78
Showing 1 changed file with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@
package org.opensearch.security.http;

import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.*;

import javax.crypto.SecretKey;

Expand All @@ -31,6 +27,7 @@
import org.junit.Test;

import org.opensearch.common.settings.Settings;
import org.opensearch.security.filter.SecurityResponse;
import org.opensearch.security.user.AuthCredentials;
import org.opensearch.security.util.FakeRestRequest;

Expand All @@ -47,6 +44,20 @@ public class OnBehalfOfAuthenticatorTest {
final static String signingKeyB64Encoded = BaseEncoding.base64().encode(signingKey.getBytes(StandardCharsets.UTF_8));
final static SecretKey secretKey = Keys.hmacShaKeyFor(signingKeyB64Encoded.getBytes(StandardCharsets.UTF_8));

@Test
public void testReRequestAuthenticationReturnsEmptyOptional() {
OnBehalfOfAuthenticator authenticator = new OnBehalfOfAuthenticator(defaultSettings(), clusterName);
Optional<SecurityResponse> result = authenticator.reRequestAuthentication(null, null);
Assert.assertFalse(result.isPresent());
}

@Test
public void testGetTypeReturnsExpectedType() {
OnBehalfOfAuthenticator authenticator = new OnBehalfOfAuthenticator(defaultSettings(), clusterName);
String type = authenticator.getType();
Assert.assertEquals("onbehalfof_jwt", type);
}

@Test
public void testNoKey() {
Exception exception = Assert.assertThrows(
Expand Down

0 comments on commit 027cd78

Please sign in to comment.