Skip to content

Commit

Permalink
Merge pull request #93 from IABTechLab/fix-oidc-typo
Browse files Browse the repository at this point in the history
Fix a typo in OIDC test
  • Loading branch information
yishi-ttd authored Jul 21, 2023
2 parents 0077992 + 28482ef commit f6b82fa
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 21 deletions.
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,18 @@
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>5.3.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import com.uid2.shared.secure.gcpoidc.TokenPayload;
import io.vertx.core.AsyncResult;
import io.vertx.core.Handler;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;

import java.nio.charset.StandardCharsets;
import java.util.Arrays;
Expand All @@ -19,7 +21,8 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.LENIENT)
public class GcpOidcAttestationProviderTest {
private static final String ATTESTATION_REQUEST = "test-attestation-request";
private static final String PUBLIC_KEY = "test-public-key";
Expand All @@ -30,17 +33,22 @@ public class GcpOidcAttestationProviderTest {

private static final TokenPayload VALID_TOKEN_PAYLOAD = TokenPayload.builder().build();

@Mock private ITokenSignatureValidator alwaysPassTokenValidator;
@Mock private ITokenSignatureValidator alwaysFailTokenValidator;
@Mock
private ITokenSignatureValidator alwaysPassTokenValidator;
@Mock
private ITokenSignatureValidator alwaysFailTokenValidator;

@Mock private IPolicyValidator alwaysPassPolicyValidator1;
@Mock
private IPolicyValidator alwaysPassPolicyValidator1;

@Mock private IPolicyValidator alwaysPassPolicyValidator2;
@Mock
private IPolicyValidator alwaysPassPolicyValidator2;

@Mock private IPolicyValidator alwaysFailPolicyValidator;
@Mock
private IPolicyValidator alwaysFailPolicyValidator;


@Before
@BeforeEach
public void setup() throws AttestationException {
when(alwaysPassTokenValidator.validate(any())).thenReturn(VALID_TOKEN_PAYLOAD);
when(alwaysFailTokenValidator.validate(any())).thenThrow(new AttestationException("token signature validation failed"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.uid2.shared.secure.gcpoidc;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import static com.uid2.shared.secure.gcpoidc.TestUtils.loadFromJson;
import static com.uid2.shared.secure.gcpoidc.TestUtils.validateAndParseToken;
Expand All @@ -10,7 +10,7 @@ public class OidcPayloadValidationTest {
@Test
public void testE2EPolicyCheck() throws Exception {
// expire at 1688132564
var payloadPath = "/com.uid2.shared/test/secure/gcpoaid/jwt_payload_policy_valid.json";
var payloadPath = "/com.uid2.shared/test/secure/gcpoidc/jwt_payload_policy_valid.json";
var payload = loadFromJson(payloadPath);
var clock = new TestClock();
clock.setCurrentTimeMs(1688132563000L);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.uid2.shared.secure.gcpoidc;

import com.uid2.shared.secure.AttestationException;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;

public class PolicyValidatorTest {
@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.uid2.shared.secure.AttestationException;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import static com.uid2.shared.secure.gcpoidc.TestUtils.loadFromJson;
import static com.uid2.shared.secure.gcpoidc.TestUtils.validateAndParseToken;
Expand All @@ -13,7 +13,7 @@ public class TokenSignatureValidatorTest {
@Test
public void testFullPayload() throws Exception {
// expire at 1688132564
var payloadPath = "/com.uid2.shared/test/secure/gcpoaid/jwt_payload_full.json";
var payloadPath = "/com.uid2.shared/test/secure/gcpoidc/jwt_payload_full.json";
var payload = loadFromJson(payloadPath);
var clock = new TestClock();
clock.setCurrentTimeMs(1688132563000L);
Expand Down Expand Up @@ -42,7 +42,7 @@ public void testFullPayload() throws Exception {
@Test
public void testPayloadWithNullValue() throws Exception {
// expire at 1688132564
var payloadPath = "/com.uid2.shared/test/secure/gcpoaid/jwt_payload_null.json";
var payloadPath = "/com.uid2.shared/test/secure/gcpoidc/jwt_payload_null.json";
var payload = loadFromJson(payloadPath);
var clock = new TestClock();
clock.setCurrentTimeMs(1688132563000L);
Expand All @@ -57,7 +57,7 @@ public void testPayloadWithNullValue() throws Exception {
@Test
public void testTokenExpired() throws Exception {
// expire at 1688132564
var payloadPath = "/com.uid2.shared/test/secure/gcpoaid/jwt_payload_null.json";
var payloadPath = "/com.uid2.shared/test/secure/gcpoidc/jwt_payload_null.json";
var payload = loadFromJson(payloadPath);
var clock = new TestClock();
clock.setCurrentTimeMs(1688132565_000L);
Expand All @@ -67,7 +67,7 @@ public void testTokenExpired() throws Exception {
@Test
public void testAudienceNotMatch() throws Exception {
// expire at 1688132564
var payloadPath = "/com.uid2.shared/test/secure/gcpoaid/jwt_payload_null.json";
var payloadPath = "/com.uid2.shared/test/secure/gcpoidc/jwt_payload_null.json";
var payload = loadFromJson(payloadPath);
payload.addProperty("aud","dummy");
var clock = new TestClock();
Expand All @@ -78,7 +78,7 @@ public void testAudienceNotMatch() throws Exception {
@Test
public void testIssuerNotMatch() throws Exception {
// expire at 1688132564
var payloadPath = "/com.uid2.shared/test/secure/gcpoaid/jwt_payload_null.json";
var payloadPath = "/com.uid2.shared/test/secure/gcpoidc/jwt_payload_null.json";
var payload = loadFromJson(payloadPath);
payload.addProperty("iss","dummy");
var clock = new TestClock();
Expand Down

0 comments on commit f6b82fa

Please sign in to comment.