|
1 | 1 | /*
|
2 |
| -* Copyright (c) 2022 Mercedes-Benz Tech Innovation GmbH |
3 |
| -* |
4 |
| -* This program and the accompanying materials are made available under the |
5 |
| -* terms of the Apache License, Version 2.0 which is available at |
6 |
| -* https://www.apache.org/licenses/LICENSE-2.0 |
7 |
| -* |
8 |
| -* SPDX-License-Identifier: Apache-2.0 |
9 |
| -* |
10 |
| -* Contributors: |
11 |
| -* Mercedes-Benz Tech Innovation GmbH - Initial API and Implementation |
12 |
| -* |
13 |
| -*/ |
| 2 | + * Copyright (c) 2022 Mercedes-Benz Tech Innovation GmbH |
| 3 | + * |
| 4 | + * This program and the accompanying materials are made available under the |
| 5 | + * terms of the Apache License, Version 2.0 which is available at |
| 6 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 7 | + * |
| 8 | + * SPDX-License-Identifier: Apache-2.0 |
| 9 | + * |
| 10 | + * Contributors: |
| 11 | + * Mercedes-Benz Tech Innovation GmbH - Initial API and Implementation |
| 12 | + * |
| 13 | + */ |
14 | 14 | package net.catenax.edc.oauth2.jwt.validation;
|
15 | 15 |
|
16 | 16 | import java.util.List;
|
17 | 17 | import java.util.Map;
|
18 |
| - |
19 | 18 | import org.eclipse.dataspaceconnector.spi.iam.ClaimToken;
|
20 | 19 | import org.eclipse.dataspaceconnector.spi.monitor.Monitor;
|
21 | 20 | import org.eclipse.dataspaceconnector.spi.result.Result;
|
|
26 | 25 |
|
27 | 26 | public class AudValidationRuleTest {
|
28 | 27 |
|
29 |
| - private static final String AUDIENCE = "audience"; |
| 28 | + private static final String AUDIENCE = "audience"; |
30 | 29 |
|
31 |
| - private AudValidationRule rule; |
| 30 | + private AudValidationRule rule; |
32 | 31 |
|
33 |
| - @BeforeEach |
34 |
| - public void setup() { |
35 |
| - final Monitor monitor = Mockito.mock(Monitor.class); |
36 |
| - rule = new AudValidationRule(AUDIENCE, monitor); |
37 |
| - } |
| 32 | + @BeforeEach |
| 33 | + public void setup() { |
| 34 | + final Monitor monitor = Mockito.mock(Monitor.class); |
| 35 | + rule = new AudValidationRule(AUDIENCE, monitor); |
| 36 | + } |
38 | 37 |
|
39 |
| - @Test |
40 |
| - void checkRuleSuccess() { |
41 |
| - final Map<String, Object> claims = Map.of("aud", List.of(AUDIENCE)); |
42 |
| - final ClaimToken token = ClaimToken.Builder.newInstance().claims(claims).build(); |
43 |
| - Result<Void> result = rule.checkRule(token, null); |
| 38 | + @Test |
| 39 | + void checkRuleSuccess() { |
| 40 | + final Map<String, Object> claims = Map.of("aud", List.of(AUDIENCE)); |
| 41 | + final ClaimToken token = ClaimToken.Builder.newInstance().claims(claims).build(); |
| 42 | + Result<Void> result = rule.checkRule(token, null); |
44 | 43 |
|
45 |
| - Assertions.assertTrue(result.succeeded()); |
46 |
| - } |
| 44 | + Assertions.assertTrue(result.succeeded()); |
| 45 | + } |
47 | 46 |
|
48 |
| - @Test |
49 |
| - void checkRuleNoClaims() { |
50 |
| - final Map<String, Object> claims = Map.of(); |
51 |
| - final ClaimToken token = ClaimToken.Builder.newInstance().claims(claims).build(); |
52 |
| - Result<Void> result = rule.checkRule(token, null); |
| 47 | + @Test |
| 48 | + void checkRuleNoClaims() { |
| 49 | + final Map<String, Object> claims = Map.of(); |
| 50 | + final ClaimToken token = ClaimToken.Builder.newInstance().claims(claims).build(); |
| 51 | + Result<Void> result = rule.checkRule(token, null); |
53 | 52 |
|
54 |
| - Assertions.assertTrue(result.succeeded()); |
55 |
| - } |
| 53 | + Assertions.assertFalse(result.succeeded()); |
| 54 | + } |
56 | 55 |
|
57 |
| - @Test |
58 |
| - void checkRuleClaimMissing() { |
59 |
| - final Map<String, Object> claims = Map.of("foo", List.of(AUDIENCE)); |
60 |
| - final ClaimToken token = ClaimToken.Builder.newInstance().claims(claims).build(); |
61 |
| - Result<Void> result = rule.checkRule(token, null); |
| 56 | + @Test |
| 57 | + void checkRuleClaimMissing() { |
| 58 | + final Map<String, Object> claims = Map.of("foo", List.of(AUDIENCE)); |
| 59 | + final ClaimToken token = ClaimToken.Builder.newInstance().claims(claims).build(); |
| 60 | + Result<Void> result = rule.checkRule(token, null); |
62 | 61 |
|
63 |
| - Assertions.assertTrue(result.succeeded()); |
64 |
| - } |
| 62 | + Assertions.assertFalse(result.succeeded()); |
| 63 | + } |
65 | 64 |
|
66 |
| - @Test |
67 |
| - void checkRuleAudNotList() { |
68 |
| - final Map<String, Object> claims = Map.of("aud", AUDIENCE); |
69 |
| - final ClaimToken token = ClaimToken.Builder.newInstance().claims(claims).build(); |
70 |
| - Result<Void> result = rule.checkRule(token, null); |
| 65 | + @Test |
| 66 | + void checkRuleAudNotList() { |
| 67 | + final Map<String, Object> claims = Map.of("aud", AUDIENCE); |
| 68 | + final ClaimToken token = ClaimToken.Builder.newInstance().claims(claims).build(); |
| 69 | + Result<Void> result = rule.checkRule(token, null); |
71 | 70 |
|
72 |
| - Assertions.assertTrue(result.succeeded()); |
73 |
| - } |
| 71 | + Assertions.assertFalse(result.succeeded()); |
| 72 | + } |
74 | 73 | }
|
0 commit comments