|
31 | 31 | */ |
32 | 32 | class JwtAudienceValidatorTests { |
33 | 33 |
|
34 | | - private final JwtAudienceValidator validatorDefault = new JwtAudienceValidator("audience"); |
35 | | - |
36 | | - private final JwtAudienceValidator validatorRequiredTrue = new JwtAudienceValidator("audience", true); |
37 | | - |
38 | | - private final JwtAudienceValidator validatorRequiredFalse = new JwtAudienceValidator("audience", false); |
| 34 | + private final JwtAudienceValidator validator = new JwtAudienceValidator("audience"); |
39 | 35 |
|
40 | 36 | @Test |
41 | | - void givenRequiredDefaultJwtWithMatchingAudienceThenShouldValidate() { |
| 37 | + void givenAllowEmptyDefaultJwtWithMatchingAudienceThenShouldValidate() { |
42 | 38 | Jwt jwt = TestJwts.jwt().audience(List.of("audience")).build(); |
43 | | - OAuth2TokenValidatorResult result = this.validatorDefault.validate(jwt); |
| 39 | + OAuth2TokenValidatorResult result = this.validator.validate(jwt); |
44 | 40 | assertThat(result).isEqualTo(OAuth2TokenValidatorResult.success()); |
45 | 41 | } |
46 | 42 |
|
47 | 43 | @Test |
48 | | - void givenRequiredJwtWithMatchingAudienceThenShouldValidate() { |
| 44 | + void givenAllowEmptyTrueJwtWithMatchingAudienceThenShouldValidate() { |
49 | 45 | Jwt jwt = TestJwts.jwt().audience(List.of("audience")).build(); |
50 | | - OAuth2TokenValidatorResult result = this.validatorRequiredTrue.validate(jwt); |
| 46 | + this.validator.setAllowEmpty(true); |
| 47 | + OAuth2TokenValidatorResult result = this.validator.validate(jwt); |
51 | 48 | assertThat(result).isEqualTo(OAuth2TokenValidatorResult.success()); |
52 | 49 | } |
53 | 50 |
|
54 | 51 | @Test |
55 | | - void givenNotRequiredJwtWithMatchingAudienceThenShouldValidate() { |
56 | | - Jwt jwt = TestJwts.jwt().audience(List.of("audience")).build(); |
57 | | - OAuth2TokenValidatorResult result = this.validatorRequiredFalse.validate(jwt); |
58 | | - assertThat(result).isEqualTo(OAuth2TokenValidatorResult.success()); |
59 | | - } |
60 | | - |
61 | | - @Test |
62 | | - void givenRequiredDefaultJwtWithoutMatchingAudienceThenShouldValidate() { |
| 52 | + void givenAllowEmptyDefaultJwtWithoutMatchingAudienceThenShouldValidate() { |
63 | 53 | Jwt jwt = TestJwts.jwt().audience(List.of("other")).build(); |
64 | | - OAuth2TokenValidatorResult result = this.validatorDefault.validate(jwt); |
| 54 | + OAuth2TokenValidatorResult result = this.validator.validate(jwt); |
65 | 55 | assertThat(result.hasErrors()).isTrue(); |
66 | 56 | } |
67 | 57 |
|
68 | 58 | @Test |
69 | | - void givenRequiredJwtWithoutMatchingAudienceThenShouldValidate() { |
| 59 | + void givenAllowEmptyJwtWithoutMatchingAudienceThenShouldValidate() { |
70 | 60 | Jwt jwt = TestJwts.jwt().audience(List.of("other")).build(); |
71 | | - OAuth2TokenValidatorResult result = this.validatorRequiredTrue.validate(jwt); |
72 | | - assertThat(result.hasErrors()).isTrue(); |
73 | | - } |
74 | | - |
75 | | - @Test |
76 | | - void givenNotRequiredJwtWithoutMatchingAudienceThenShouldValidate() { |
77 | | - Jwt jwt = TestJwts.jwt().audience(List.of("other")).build(); |
78 | | - OAuth2TokenValidatorResult result = this.validatorRequiredFalse.validate(jwt); |
79 | | - assertThat(result.hasErrors()).isTrue(); |
80 | | - } |
81 | | - |
82 | | - @Test |
83 | | - void givenRequiredDefaultJwtWithoutAudienceThenShouldValidate() { |
84 | | - Jwt jwt = TestJwts.jwt().audience(null).build(); |
85 | | - OAuth2TokenValidatorResult result = this.validatorDefault.validate(jwt); |
| 61 | + this.validator.setAllowEmpty(true); |
| 62 | + OAuth2TokenValidatorResult result = this.validator.validate(jwt); |
86 | 63 | assertThat(result.hasErrors()).isTrue(); |
87 | 64 | } |
88 | 65 |
|
89 | 66 | @Test |
90 | | - void givenRequiredJwtWithoutAudienceThenShouldValidate() { |
| 67 | + void givenAllowEmptyDefaultJwtWithoutAudienceThenShouldValidate() { |
91 | 68 | Jwt jwt = TestJwts.jwt().audience(null).build(); |
92 | | - OAuth2TokenValidatorResult result = this.validatorRequiredTrue.validate(jwt); |
| 69 | + OAuth2TokenValidatorResult result = this.validator.validate(jwt); |
93 | 70 | assertThat(result.hasErrors()).isTrue(); |
94 | 71 | } |
95 | 72 |
|
96 | 73 | @Test |
97 | | - void givenNotRequiredJwtWithoutAudienceThenShouldValidate() { |
| 74 | + void givenAllowEmptyTrueJwtWithoutAudienceThenShouldValidate() { |
98 | 75 | Jwt jwt = TestJwts.jwt().audience(null).build(); |
99 | | - OAuth2TokenValidatorResult result = this.validatorRequiredFalse.validate(jwt); |
| 76 | + this.validator.setAllowEmpty(true); |
| 77 | + OAuth2TokenValidatorResult result = this.validator.validate(jwt); |
100 | 78 | assertThat(result.hasErrors()).isFalse(); |
101 | 79 | } |
102 | 80 |
|
|
0 commit comments