Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MGRTENANT-10 Support underscore for tenant name #22

Merged
merged 2 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/main/resources/swagger.api/schemas/tenant.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
"name": {
"description": "Tenant name",
"type": "string",
"pattern": "[a-z][a-z0-9]{0,30}"
"pattern": "[a-z][a-z0-9_]{0,29}[a-z0-9]"
},
"description": {
"description": "Tenant description",
"type": "string"
},
"type": {
"description": "Tenant type",
"$ref": "tenantType.json"
},
"attributes": {
Expand Down
42 changes: 36 additions & 6 deletions src/test/java/org/folio/tm/it/TenantKeycloakIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,34 @@ void create_tenant_positive() throws Exception {
assertThat(mappers).containsAll(expectedMappers);
}

private Map<String, String> requestBody() {
var loginRequest = new HashMap<String, String>();
loginRequest.put("client_id", clientId);
loginRequest.put("client_secret", clientSecret);
loginRequest.put("grant_type", grantType);
return loginRequest;
@Test
void createTenant_positive_nameContainingUnderscore() throws Exception {
var tenantName = "test_tenant";
var tenant = new Tenant().name(tenantName).description("Test tenant with underscore in name");
var token = keycloakClient.login(requestBody());
mockMvc.perform(post("/tenants")
.contentType(APPLICATION_JSON)
.header(TOKEN, token.getAccessToken())
.content(TestUtils.asJsonString(tenant)))
.andExpect(status().isCreated())
.andExpect(jsonPath("$.id", is(notNullValue())))
.andExpect(jsonPath("$.name", is(tenantName)))
.andExpect(jsonPath("$.description", is(tenant.getDescription())))
.andExpect(jsonPath("$.type", is(tenant.getType().getValue())))
.andExpect(jsonPath("$.metadata", is(notNullValue())));

assertTrue(keycloakRealmService.isRealmExist(tenantName));
assertNull(okapiService);

var client = keycloakClientService.findClientByClientId(tenantName, "impersonation-client");
var mappers = client.getProtocolMappers();

var expectedMappers = List.of(
protocolMapper(USER_PROPERTY_MAPPER_TYPE, "username", "username", "sub"),
protocolMapper(USER_ATTRIBUTE_MAPPER_TYPE, "user_id mapper", "user_id", "user_id")
);

assertThat(mappers).containsAll(expectedMappers);
}

@Test
Expand Down Expand Up @@ -192,4 +214,12 @@ private static Tenant copyFrom() {

return result;
}

private Map<String, String> requestBody() {
var loginRequest = new HashMap<String, String>();
loginRequest.put("client_id", clientId);
loginRequest.put("client_secret", clientSecret);
loginRequest.put("grant_type", grantType);
return loginRequest;
}
}