@@ -42,6 +42,8 @@ public class ResourceServerPropertiesTests {
42
42
private ResourceServerProperties properties = new ResourceServerProperties ("client" ,
43
43
"secret" );
44
44
45
+ private Errors errors = mock (Errors .class );
46
+
45
47
@ Test
46
48
@ SuppressWarnings ("unchecked" )
47
49
public void json () throws Exception {
@@ -54,39 +56,109 @@ public void json() throws Exception {
54
56
}
55
57
56
58
@ Test
57
- public void tokenKeyDerivedFromUserInfoUri () throws Exception {
58
- this .properties .setUserInfoUri ("http://example.com/userinfo" );
59
- assertThat (this .properties .getJwt ().getKeyUri ())
60
- .isEqualTo ("http://example.com/token_key" );
59
+ public void validateWhenBothJwtAndJwkKeyUrisPresentShouldFail () throws Exception {
60
+ this .properties .getJwk ().setKeySetUri ("http://my-auth-server/token_keys" );
61
+ this .properties .getJwt ().setKeyUri ("http://my-auth-server/token_key" );
62
+ setListableBeanFactory ();
63
+ this .properties .validate (this .properties , this .errors );
64
+ verify (this .errors ).reject ("ambiguous.keyUri" ,
65
+ "Only one of jwt.keyUri (or jwt.keyValue) and jwk.keySetUri should be configured." );
61
66
}
62
67
63
68
@ Test
64
- public void tokenKeyDerivedFromTokenInfoUri () throws Exception {
65
- this .properties .setTokenInfoUri ("http://example.com/check_token" );
66
- assertThat (this .properties .getJwt ().getKeyUri ())
67
- .isEqualTo ("http://example.com/token_key" );
69
+ public void validateWhenBothJwtKeyValueAndJwkKeyUriPresentShouldFail ()
70
+ throws Exception {
71
+ this .properties .getJwk ().setKeySetUri ("http://my-auth-server/token_keys" );
72
+ this .properties .getJwt ().setKeyValue ("my-key" );
73
+ setListableBeanFactory ();
74
+ this .properties .validate (this .properties , this .errors );
75
+ verify (this .errors ).reject ("ambiguous.keyUri" ,
76
+ "Only one of jwt.keyUri (or jwt.keyValue) and jwk.keySetUri should be configured." );
68
77
}
69
78
70
79
@ Test
71
- public void validateWhenBothJwtAndJwtKeyConfigurationPresentShouldFail ()
72
- throws Exception {
80
+ public void validateWhenJwkKeySetUriProvidedShouldSucceed () throws Exception {
73
81
this .properties .getJwk ().setKeySetUri ("http://my-auth-server/token_keys" );
74
- this .properties .getJwt ().setKeyUri ("http://my-auth-server/token_key" );
75
82
setListableBeanFactory ();
76
- Errors errors = mock (Errors .class );
77
- this .properties .validate (this .properties , errors );
78
- verify (errors ).reject ("ambiguous.keyUri" ,
79
- "Only one of jwt.keyUri (or jwt.keyValue) and jwk.keySetUri should be configured." );
83
+ this .properties .validate (this .properties , this .errors );
84
+ verifyZeroInteractions (this .errors );
85
+ }
80
86
87
+ @ Test
88
+ public void validateWhenKeyValuePresentShouldSucceed () throws Exception {
89
+ this .properties .getJwt ().setKeyValue ("my-key" );
90
+ setListableBeanFactory ();
91
+ this .properties .validate (this .properties , this .errors );
92
+ verifyZeroInteractions (this .errors );
81
93
}
82
94
83
95
@ Test
84
- public void validateWhenKeySetUriProvidedShouldSucceed () throws Exception {
96
+ public void validateWhenKeysUriOrValuePresentAndUserInfoAbsentShouldNotFail ()
97
+ throws Exception {
98
+ this .properties = new ResourceServerProperties ("client" , "" );
85
99
this .properties .getJwk ().setKeySetUri ("http://my-auth-server/token_keys" );
86
100
setListableBeanFactory ();
87
- Errors errors = mock (Errors .class );
88
- this .properties .validate (this .properties , errors );
89
- verifyZeroInteractions (errors );
101
+ this .properties .validate (this .properties , this .errors );
102
+ verifyZeroInteractions (this .errors );
103
+ }
104
+
105
+ @ Test
106
+ public void validateWhenKeyConfigAbsentAndInfoUrisNotConfiguredShouldFail ()
107
+ throws Exception {
108
+ setListableBeanFactory ();
109
+ this .properties .validate (this .properties , this .errors );
110
+ verify (this .errors ).rejectValue ("tokenInfoUri" , "missing.tokenInfoUri" ,
111
+ "Missing tokenInfoUri and userInfoUri and there is no JWT verifier key" );
112
+ }
113
+
114
+ @ Test
115
+ public void validateWhenTokenUriConfiguredShouldNotFail () throws Exception {
116
+ this .properties .setTokenInfoUri ("http://my-auth-server/userinfo" );
117
+ setListableBeanFactory ();
118
+ this .properties .validate (this .properties , this .errors );
119
+ verifyZeroInteractions (this .errors );
120
+ }
121
+
122
+ @ Test
123
+ public void validateWhenUserInfoUriConfiguredShouldNotFail () throws Exception {
124
+ this .properties .setUserInfoUri ("http://my-auth-server/userinfo" );
125
+ setListableBeanFactory ();
126
+ this .properties .validate (this .properties , this .errors );
127
+ verifyZeroInteractions (this .errors );
128
+ }
129
+
130
+ @ Test
131
+ public void validateWhenTokenUriPreferredAndClientSecretAbsentShouldFail ()
132
+ throws Exception {
133
+ this .properties = new ResourceServerProperties ("client" , "" );
134
+ this .properties .setTokenInfoUri ("http://my-auth-server/check_token" );
135
+ this .properties .setUserInfoUri ("http://my-auth-server/userinfo" );
136
+ setListableBeanFactory ();
137
+ this .properties .validate (this .properties , this .errors );
138
+ verify (this .errors ).rejectValue ("clientSecret" , "missing.clientSecret" ,
139
+ "Missing client secret" );
140
+ }
141
+
142
+ @ Test
143
+ public void validateWhenTokenUriAbsentAndClientSecretAbsentShouldNotFail ()
144
+ throws Exception {
145
+ this .properties = new ResourceServerProperties ("client" , "" );
146
+ this .properties .setUserInfoUri ("http://my-auth-server/userinfo" );
147
+ setListableBeanFactory ();
148
+ this .properties .validate (this .properties , this .errors );
149
+ verifyZeroInteractions (this .errors );
150
+ }
151
+
152
+ @ Test
153
+ public void validateWhenTokenUriNotPreferredAndClientSecretAbsentShouldNotFail ()
154
+ throws Exception {
155
+ this .properties = new ResourceServerProperties ("client" , "" );
156
+ this .properties .setPreferTokenInfo (false );
157
+ this .properties .setTokenInfoUri ("http://my-auth-server/check_token" );
158
+ this .properties .setUserInfoUri ("http://my-auth-server/userinfo" );
159
+ setListableBeanFactory ();
160
+ this .properties .validate (this .properties , this .errors );
161
+ verifyZeroInteractions (this .errors );
90
162
}
91
163
92
164
private void setListableBeanFactory () {
0 commit comments