Skip to content
This repository was archived by the owner on May 14, 2025. It is now read-only.

Commit 0219809

Browse files
author
Corneil du Plessis
committed
Fix duplicate output for skipper and dataflow and some output frames.
Refactor DefaultAuthoritiesMapperTests for JUnit 5 conventions. Rename DataflowOAuthIT methods for JUnit 5 conventions. Add testcontainers-keycloak to dependency management in spring-cloud-dataflow-parent.
1 parent bc49898 commit 0219809

File tree

8 files changed

+302
-281
lines changed

8 files changed

+302
-281
lines changed

spring-cloud-common-security-config/spring-cloud-common-security-config-web/src/test/java/org/springframework/cloud/common/security/support/DefaultAuthoritiesMapperTests.java

Lines changed: 113 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,17 @@
3434
/**
3535
* @author Gunnar Hillert
3636
*/
37-
public class DefaultAuthoritiesMapperTests {
37+
class DefaultAuthoritiesMapperTests {
3838

3939
@Test
40-
public void testNullConstructor() throws Exception {
40+
void nullConstructor() throws Exception {
4141
assertThatThrownBy(() -> {
4242
new DefaultAuthoritiesMapper(null, "");
4343
}).isInstanceOf(IllegalArgumentException.class).hasMessageContaining("providerRoleMappings must not be null.");
4444
}
4545

4646
@Test
47-
public void testMapScopesToAuthoritiesWithNullParameters() throws Exception {
47+
void mapScopesToAuthoritiesWithNullParameters() throws Exception {
4848
DefaultAuthoritiesMapper authoritiesMapper = new DefaultAuthoritiesMapper(Collections.emptyMap(), "");
4949

5050
assertThatThrownBy(() -> {
@@ -56,18 +56,19 @@ public void testMapScopesToAuthoritiesWithNullParameters() throws Exception {
5656
}
5757

5858
@Test
59-
public void testThat7AuthoritiesAreReturned() throws Exception {
59+
void that7AuthoritiesAreReturned() throws Exception {
6060
DefaultAuthoritiesMapper authoritiesMapper = new DefaultAuthoritiesMapper("uaa", false);
6161
Set<GrantedAuthority> authorities = authoritiesMapper.mapScopesToAuthorities("uaa", Collections.emptySet(), null);
6262

6363
assertThat(authorities).hasSize(7);
64-
assertThat(authorities.stream().map(authority -> authority.getAuthority()).collect(Collectors.toList()))
64+
assertThat(authorities)
65+
.extracting(GrantedAuthority::getAuthority)
6566
.containsExactlyInAnyOrder("ROLE_MANAGE", "ROLE_CREATE", "ROLE_VIEW", "ROLE_DEPLOY", "ROLE_MODIFY",
6667
"ROLE_SCHEDULE", "ROLE_DESTROY");
6768
}
6869

6970
@Test
70-
public void testEmptyMapConstructor() throws Exception {
71+
void emptyMapConstructor() throws Exception {
7172
Set<String> scopes = new HashSet<>();
7273
scopes.add("dataflow.manage");
7374
scopes.add("dataflow.view");
@@ -77,12 +78,13 @@ public void testEmptyMapConstructor() throws Exception {
7778
Collection<? extends GrantedAuthority> authorities = authoritiesMapper.mapScopesToAuthorities("uaa", scopes, null);
7879

7980
assertThat(authorities).hasSize(3);
80-
assertThat(authorities.stream().map(authority -> authority.getAuthority()).collect(Collectors.toList()))
81+
assertThat(authorities)
82+
.extracting(GrantedAuthority::getAuthority)
8183
.containsExactlyInAnyOrder("ROLE_MANAGE", "ROLE_CREATE", "ROLE_VIEW");
8284
}
8385

8486
@Test
85-
public void testMapConstructorWithIncompleteRoleMappings() throws Exception {
87+
void mmapConstructorWithIncompleteRoleMappings() throws Exception {
8688
ProviderRoleMapping roleMapping = new ProviderRoleMapping();
8789
roleMapping.setMapOauthScopes(true);
8890
roleMapping.addRoleMapping("ROLE_MANAGE", "foo-scope-in-oauth");
@@ -93,107 +95,115 @@ public void testMapConstructorWithIncompleteRoleMappings() throws Exception {
9395
}
9496

9597
@Test
96-
public void testThat3MappedAuthoritiesAreReturned() throws Exception {
97-
Map<String, String> roleMappings = new HashMap<>();
98-
roleMappings.put("ROLE_MANAGE", "dataflow_manage");
99-
roleMappings.put("ROLE_VIEW", "dataflow_view");
100-
roleMappings.put("ROLE_CREATE", "dataflow_create");
101-
roleMappings.put("ROLE_MODIFY", "dataflow_modify");
102-
roleMappings.put("ROLE_DEPLOY", "dataflow_deploy");
103-
roleMappings.put("ROLE_DESTROY", "dataflow_destroy");
104-
roleMappings.put("ROLE_SCHEDULE", "dataflow_schedule");
98+
void that3MappedAuthoritiesAreReturned() throws Exception {
99+
Map<String, String> roleMappings = Map.of(
100+
"ROLE_MANAGE", "dataflow_manage",
101+
"ROLE_VIEW", "dataflow_view",
102+
"ROLE_CREATE", "dataflow_create",
103+
"ROLE_MODIFY", "dataflow_modify",
104+
"ROLE_DEPLOY", "dataflow_deploy",
105+
"ROLE_DESTROY", "dataflow_destroy",
106+
"ROLE_SCHEDULE", "dataflow_schedule"
107+
);
105108

106109
ProviderRoleMapping providerRoleMapping = new ProviderRoleMapping();
107110
providerRoleMapping.setMapOauthScopes(true);
108111
providerRoleMapping.getRoleMappings().putAll(roleMappings);
109112

110-
Set<String> roles = new HashSet<>();
111-
roles.add("dataflow_manage");
112-
roles.add("dataflow_view");
113-
roles.add("dataflow_deploy");
113+
Set<String> roles = Set.of("dataflow_manage", "dataflow_view", "dataflow_deploy");
114114

115115
DefaultAuthoritiesMapper defaultAuthoritiesMapper = new DefaultAuthoritiesMapper("uaa", providerRoleMapping);
116116
Collection<? extends GrantedAuthority> authorities = defaultAuthoritiesMapper.mapScopesToAuthorities("uaa",
117117
roles, null);
118118

119119
assertThat(authorities).hasSize(3);
120-
assertThat(authorities.stream().map(authority -> authority.getAuthority()).collect(Collectors.toList()))
120+
assertThat(authorities)
121+
.extracting(GrantedAuthority::getAuthority)
121122
.containsExactlyInAnyOrder("ROLE_DEPLOY", "ROLE_MANAGE", "ROLE_VIEW");
122123
}
123-
public void testThat7MappedAuthoritiesAreReturned() throws Exception {
124-
Map<String, String> roleMappings = new HashMap<>();
125-
roleMappings.put("ROLE_MANAGE", "foo-manage");
126-
roleMappings.put("ROLE_VIEW", "bar-view");
127-
roleMappings.put("ROLE_CREATE", "blubba-create");
128-
roleMappings.put("ROLE_MODIFY", "foo-modify");
129-
roleMappings.put("ROLE_DEPLOY", "foo-deploy");
130-
roleMappings.put("ROLE_DESTROY", "foo-destroy");
131-
roleMappings.put("ROLE_SCHEDULE", "foo-schedule");
124+
@Test
125+
void that7MappedAuthoritiesAreReturned() throws Exception {
126+
Map<String, String> roleMappings = Map.of(
127+
"ROLE_MANAGE", "foo-manage",
128+
"ROLE_VIEW", "bar-view",
129+
"ROLE_CREATE", "blubba-create",
130+
"ROLE_MODIFY", "foo-modify",
131+
"ROLE_DEPLOY", "foo-deploy",
132+
"ROLE_DESTROY", "foo-destroy",
133+
"ROLE_SCHEDULE", "foo-schedule"
134+
);
132135

133136
ProviderRoleMapping providerRoleMapping = new ProviderRoleMapping();
134137
providerRoleMapping.setMapOauthScopes(true);
135138
providerRoleMapping.getRoleMappings().putAll(roleMappings);
136139

137-
Set<String> scopes = new HashSet<>();
138-
scopes.add("foo-manage");
139-
scopes.add("bar-view");
140-
scopes.add("blubba-create");
141-
scopes.add("foo-modify");
142-
scopes.add("foo-deploy");
143-
scopes.add("foo-destroy");
144-
scopes.add("foo-schedule");
140+
Set<String> scopes = Set.of(
141+
"foo-manage",
142+
"bar-view",
143+
"blubba-create",
144+
"foo-modify",
145+
"foo-deploy",
146+
"foo-destroy",
147+
"foo-schedule"
148+
);
145149

146150
DefaultAuthoritiesMapper defaultAuthoritiesMapper = new DefaultAuthoritiesMapper("uaa", providerRoleMapping);
147151
Collection<? extends GrantedAuthority> authorities = defaultAuthoritiesMapper.mapScopesToAuthorities("uaa",
148152
scopes, null);
149153

150154
assertThat(authorities).hasSize(7);
151-
assertThat(authorities.stream().map(authority -> authority.getAuthority()).collect(Collectors.toList()))
155+
assertThat(authorities)
156+
.extracting(GrantedAuthority::getAuthority)
152157
.containsExactlyInAnyOrder("ROLE_CREATE", "ROLE_DEPLOY", "ROLE_DESTROY", "ROLE_MANAGE", "ROLE_MODIFY",
153158
"ROLE_SCHEDULE", "ROLE_VIEW");
154159
}
155160

156161
@Test
157-
public void testThat3MappedAuthoritiesAreReturnedForDefaultMapping() throws Exception {
162+
void that3MappedAuthoritiesAreReturnedForDefaultMapping() throws Exception {
158163
ProviderRoleMapping providerRoleMapping = new ProviderRoleMapping();
159164
providerRoleMapping.setMapOauthScopes(true);
160165

161-
Set<String> scopes = new HashSet<>();
162-
scopes.add("dataflow.manage");
163-
scopes.add("dataflow.view");
164-
scopes.add("dataflow.create");
166+
Set<String> scopes = Set.of(
167+
"dataflow.manage",
168+
"dataflow.view",
169+
"dataflow.create"
170+
);
165171

166172
DefaultAuthoritiesMapper defaultAuthoritiesExtractor = new DefaultAuthoritiesMapper("uaa", providerRoleMapping);
167173
Collection<? extends GrantedAuthority> authorities = defaultAuthoritiesExtractor.mapScopesToAuthorities("uaa",
168174
scopes, null);
169175

170176
assertThat(authorities).hasSize(3);
171-
assertThat(authorities.stream().map(authority -> authority.getAuthority()).collect(Collectors.toList()))
177+
assertThat(authorities)
178+
.extracting(GrantedAuthority::getAuthority)
172179
.containsExactlyInAnyOrder("ROLE_MANAGE", "ROLE_CREATE", "ROLE_VIEW");
173180
}
174181

175182
@Test
176-
public void testThat7MappedAuthoritiesAreReturnedForDefaultMappingWithoutMappingScopes() throws Exception {
177-
Set<String> scopes = new HashSet<>();
178-
scopes.add("dataflow.manage");
179-
scopes.add("dataflow.view");
180-
scopes.add("dataflow.create");
183+
void that7MappedAuthoritiesAreReturnedForDefaultMappingWithoutMappingScopes() throws Exception {
184+
Set<String> scopes = Set.of(
185+
"dataflow.manage",
186+
"dataflow.view",
187+
"dataflow.create"
188+
);
181189

182190
DefaultAuthoritiesMapper defaultAuthoritiesExtractor = new DefaultAuthoritiesMapper("uaa", false);
183191
Collection<? extends GrantedAuthority> authorities = defaultAuthoritiesExtractor.mapScopesToAuthorities("uaa",
184192
scopes, null);
185193

186194
assertThat(authorities).hasSize(7);
187-
assertThat(authorities.stream().map(authority -> authority.getAuthority()).collect(Collectors.toList()))
195+
assertThat(authorities)
196+
.extracting(GrantedAuthority::getAuthority)
188197
.containsExactlyInAnyOrder("ROLE_CREATE", "ROLE_DEPLOY", "ROLE_DESTROY", "ROLE_MANAGE", "ROLE_MODIFY",
189198
"ROLE_SCHEDULE", "ROLE_VIEW");
190199
}
191200

192201
@Test
193-
public void testThat2MappedAuthoritiesAreReturnedForDefaultMapping() throws Exception {
194-
Set<String> scopes = new HashSet<>();
195-
scopes.add("dataflow.view");
196-
scopes.add("dataflow.create");
202+
void that2MappedAuthoritiesAreReturnedForDefaultMapping() throws Exception {
203+
Set<String> scopes = Set.of(
204+
"dataflow.view",
205+
"dataflow.create"
206+
);
197207

198208
DefaultAuthoritiesMapper defaultAuthoritiesExtractor = new DefaultAuthoritiesMapper("uaa", true);
199209
Collection<? extends GrantedAuthority> authorities = defaultAuthoritiesExtractor.mapScopesToAuthorities("uaa",
@@ -205,19 +215,18 @@ public void testThat2MappedAuthoritiesAreReturnedForDefaultMapping() throws Exce
205215
}
206216

207217
@Test
208-
public void testThat7AuthoritiesAreReturnedAndOneOAuthScopeCoversMultipleServerRoles() throws Exception {
209-
Map<String, String> roleMappings = new HashMap<>();
210-
roleMappings.put("ROLE_MANAGE", "foo-manage");
211-
roleMappings.put("ROLE_VIEW", "foo-manage");
212-
roleMappings.put("ROLE_DEPLOY", "foo-manage");
213-
roleMappings.put("ROLE_DESTROY", "foo-manage");
214-
roleMappings.put("ROLE_MODIFY", "foo-manage");
215-
roleMappings.put("ROLE_SCHEDULE", "foo-manage");
216-
roleMappings.put("ROLE_CREATE", "blubba-create");
217-
218-
Set<String> scopes = new HashSet<>();
219-
scopes.add("foo-manage");
220-
scopes.add("blubba-create");
218+
void that7AuthoritiesAreReturnedAndOneOAuthScopeCoversMultipleServerRoles() throws Exception {
219+
Map<String, String> roleMappings = Map.of(
220+
"ROLE_MANAGE", "foo-manage",
221+
"ROLE_VIEW", "foo-manage",
222+
"ROLE_DEPLOY", "foo-manage",
223+
"ROLE_DESTROY", "foo-manage",
224+
"ROLE_MODIFY", "foo-manage",
225+
"ROLE_SCHEDULE", "foo-manage",
226+
"ROLE_CREATE", "blubba-create"
227+
);
228+
229+
Set<String> scopes = Set.of("foo-manage", "blubba-create");
221230

222231
DefaultAuthoritiesMapper defaultAuthoritiesExtractor = new DefaultAuthoritiesMapper("uaa", true, roleMappings);
223232
Collection<? extends GrantedAuthority> authorities = defaultAuthoritiesExtractor.mapScopesToAuthorities("uaa",
@@ -230,61 +239,64 @@ public void testThat7AuthoritiesAreReturnedAndOneOAuthScopeCoversMultipleServerR
230239
}
231240

232241
@Test
233-
public void testThatUriStyleScopeRemovesLeadingPart() throws Exception {
234-
Map<String, String> roleMappings = new HashMap<>();
235-
roleMappings.put("ROLE_MANAGE", "foo-manage");
236-
roleMappings.put("ROLE_VIEW", "foo-manage");
237-
roleMappings.put("ROLE_DEPLOY", "foo-manage");
238-
roleMappings.put("ROLE_DESTROY", "foo-manage");
239-
roleMappings.put("ROLE_MODIFY", "foo-manage");
240-
roleMappings.put("ROLE_SCHEDULE", "foo-manage");
241-
roleMappings.put("ROLE_CREATE", "blubba-create");
242-
243-
Set<String> scopes = new HashSet<>();
244-
scopes.add("api://foobar/foo-manage");
245-
scopes.add("blubba-create");
242+
void thatUriStyleScopeRemovesLeadingPart() throws Exception {
243+
Map<String, String> roleMappings = Map.of(
244+
"ROLE_MANAGE", "foo-manage",
245+
"ROLE_VIEW", "foo-manage",
246+
"ROLE_DEPLOY", "foo-manage",
247+
"ROLE_DESTROY", "foo-manage",
248+
"ROLE_MODIFY", "foo-manage",
249+
"ROLE_SCHEDULE", "foo-manage",
250+
"ROLE_CREATE", "blubba-create"
251+
);
252+
253+
Set<String> scopes = Set.of("api://foobar/foo-manage", "blubba-create");
246254

247255
DefaultAuthoritiesMapper defaultAuthoritiesExtractor = new DefaultAuthoritiesMapper("uaa", true, roleMappings);
248256
Collection<? extends GrantedAuthority> authorities = defaultAuthoritiesExtractor.mapScopesToAuthorities("uaa",
249257
scopes, null);
250258

251259
assertThat(authorities).hasSize(7);
252-
assertThat(authorities.stream().map(authority -> authority.getAuthority()).collect(Collectors.toList()))
260+
assertThat(authorities)
261+
.extracting(GrantedAuthority::getAuthority)
253262
.containsExactlyInAnyOrder("ROLE_CREATE", "ROLE_DEPLOY", "ROLE_DESTROY", "ROLE_MANAGE", "ROLE_MODIFY",
254263
"ROLE_SCHEDULE", "ROLE_VIEW");
255264
}
256265

257266
@Test
258-
public void testThatUriStyleScopeParsingCanBeDisabled() throws Exception {
259-
Map<String, String> roleMappings = new HashMap<>();
260-
roleMappings.put("ROLE_MANAGE", "/ROLE/2000803042");
261-
roleMappings.put("ROLE_VIEW", "/ROLE/2000803036");
262-
roleMappings.put("ROLE_DEPLOY", "/ROLE/2000803039");
263-
roleMappings.put("ROLE_DESTROY", "/ROLE/20008030340");
264-
roleMappings.put("ROLE_MODIFY", "/ROLE/2000803037");
265-
roleMappings.put("ROLE_SCHEDULE", "/ROLE/2000803038");
266-
roleMappings.put("ROLE_CREATE", "/ROLE/2000803041");
267+
void thatUriStyleScopeParsingCanBeDisabled() throws Exception {
268+
Map<String, String> roleMappings = Map.of(
269+
"ROLE_MANAGE", "/ROLE/2000803042",
270+
"ROLE_VIEW", "/ROLE/2000803036",
271+
"ROLE_DEPLOY", "/ROLE/2000803039",
272+
"ROLE_DESTROY", "/ROLE/20008030340",
273+
"ROLE_MODIFY", "/ROLE/2000803037",
274+
"ROLE_SCHEDULE", "/ROLE/2000803038",
275+
"ROLE_CREATE", "/ROLE/2000803041"
276+
);
267277

268278
ProviderRoleMapping providerRoleMapping = new ProviderRoleMapping();
269279
providerRoleMapping.setMapOauthScopes(true);
270280
providerRoleMapping.setParseOauthScopePathParts(false);
271281
providerRoleMapping.getRoleMappings().putAll(roleMappings);
272282

273-
Set<String> scopes = new HashSet<>();
274-
scopes.add("/ROLE/2000803042");
275-
scopes.add("/ROLE/2000803036");
276-
scopes.add("/ROLE/2000803039");
277-
scopes.add("/ROLE/20008030340");
278-
scopes.add("/ROLE/2000803037");
279-
scopes.add("/ROLE/2000803038");
280-
scopes.add("/ROLE/2000803041");
283+
Set<String> scopes = Set.of(
284+
"/ROLE/2000803042",
285+
"/ROLE/2000803036",
286+
"/ROLE/2000803039",
287+
"/ROLE/20008030340",
288+
"/ROLE/2000803037",
289+
"/ROLE/2000803038",
290+
"/ROLE/2000803041"
291+
);
281292

282293
DefaultAuthoritiesMapper defaultAuthoritiesMapper = new DefaultAuthoritiesMapper("uaa", providerRoleMapping);
283294
Collection<? extends GrantedAuthority> authorities = defaultAuthoritiesMapper.mapScopesToAuthorities("uaa",
284295
scopes, null);
285296

286297
assertThat(authorities).hasSize(7);
287-
assertThat(authorities.stream().map(authority -> authority.getAuthority()).collect(Collectors.toList()))
298+
assertThat(authorities)
299+
.extracting(GrantedAuthority::getAuthority)
288300
.containsExactlyInAnyOrder("ROLE_CREATE", "ROLE_DEPLOY", "ROLE_DESTROY", "ROLE_MANAGE", "ROLE_MODIFY",
289301
"ROLE_SCHEDULE", "ROLE_VIEW");
290302
}

spring-cloud-dataflow-parent/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
<!-- database driver versions -->
6363
<oracle-ojdbc8.version>21.9.0.0</oracle-ojdbc8.version>
6464
<db2-jcc.version>11.5.9.0</db2-jcc.version>
65+
<testcontainers-keycloak.version>3.4.0</testcontainers-keycloak.version>
6566
<!-- questionable testing libs -->
6667
<org-json.version>20240303</org-json.version>
6768
<littleproxy.version>1.1.2</littleproxy.version>
@@ -257,6 +258,11 @@
257258
<type>pom</type>
258259
<scope>import</scope>
259260
</dependency>
261+
<dependency>
262+
<groupId>com.github.dasniko</groupId>
263+
<artifactId>testcontainers-keycloak</artifactId>
264+
<version>${testcontainers-keycloak.version}</version>
265+
</dependency>
260266
</dependencies>
261267
</dependencyManagement>
262268
<dependencies>

spring-cloud-dataflow-server/pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@
112112
<dependency>
113113
<groupId>com.github.dasniko</groupId>
114114
<artifactId>testcontainers-keycloak</artifactId>
115-
<version>3.4.0</version>
116115
<scope>test</scope>
117116
</dependency>
118117
<dependency>

spring-cloud-dataflow-server/src/main/resources/application.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ spring:
2828
url: "{repository}/org/springframework/cloud/spring-cloud-dataflow-shell/{version}/spring-cloud-dataflow-shell-{version}.jar"
2929
checksum-sha1-url: "{repository}/org/springframework/cloud/spring-cloud-dataflow-shell/{version}/spring-cloud-dataflow-shell-{version}.jar.sha1"
3030
checksum-sha256-url: "{repository}/org/springframework/cloud/spring-cloud-dataflow-shell/{version}/spring-cloud-dataflow-shell-{version}.jar.sha256"
31-
3231
jpa:
3332
hibernate:
3433
ddl-auto: none

0 commit comments

Comments
 (0)