diff --git a/gravitee-am-repository/gravitee-am-repository-jdbc/src/main/resources/liquibase/changelogs/v4_2_27/4.2.27-change-client-column-size.yml b/gravitee-am-repository/gravitee-am-repository-jdbc/src/main/resources/liquibase/changelogs/v4_2_27/4.2.27-change-client-column-size.yml new file mode 100644 index 00000000000..0af6ce0e901 --- /dev/null +++ b/gravitee-am-repository/gravitee-am-repository-jdbc/src/main/resources/liquibase/changelogs/v4_2_27/4.2.27-change-client-column-size.yml @@ -0,0 +1,183 @@ +# Change client column from 64 to 255 characters. +databaseChangeLog: + - changeSet: + id: 4.2.27-change-client-column-size-scope-approval-new-field # remove index introduced in 4.5.0 + author: GraviteeSource Team + dbms: mssql + onError: MARK_RAN + preConditions: + - onFail: MARK_RAN + - indexExists: + tableName: scope_approvals + indexName: idx_scope_approvals_domain_client_user_id_extid_scope + changes: + - dropIndex: + indexName: idx_scope_approvals_domain_client_user_id_extid_scope + tableName: scope_approvals + - changeSet: + id: 4.2.27-change-client-column-size-remove-indexes # MSSQL SERVER needs to first remove index before changing type + author: GraviteeSource Team + dbms: mssql + changes: + # device + - dropIndex: + tableName: devices + indexName: idx_devices_domain_client_user + # scope_approvals + - dropIndex: + indexName: idx_scope_approvals_domain_client_user_scope + tableName: scope_approvals + + #access_tokens + - dropIndex: + indexName: idx_access_tokens_client + tableName: access_tokens + - dropIndex: + indexName: idx_access_tokens_domain_client_subject + tableName: access_tokens + + #refresh_tokens + - dropIndex: + indexName: idx_refresh_tokens_client + tableName: refresh_tokens + - dropIndex: + indexName: idx_refresh_tokens_domain_client_subject + tableName: refresh_tokens + + - changeSet: + id: 4.2.27-change-client-column-size + author: GraviteeSource Team + changes: + #devices + - dropIndex: + tableName: devices + indexName: idx_devices_domain_client_user_remember_device_device_id + - modifyDataType: + tableName: devices + columnName: client + newDataType: VARCHAR(255) + - createIndex: # removed index for reference type to be able to change data type of client and not exceed max index length + columns: + - column: + name: reference_id + - column: + name: client + - column: + name: user_id + - column: + name: device_identifier_id + - column: + name: device_id + indexName: idx_devices_domain_client_user_remember_device_device_id + tableName: devices + unique: false + + # scope_approvals + - modifyDataType: + tableName: scope_approvals + columnName: client_id + newDataType: VARCHAR(255) + + #access_tokens + - modifyDataType: + tableName: access_tokens + columnName: client + newDataType: VARCHAR(255) + + #refresh_tokens + - modifyDataType: + tableName: refresh_tokens + columnName: client + newDataType: VARCHAR(255) + + #authorization_codes + - modifyDataType: + tableName: authorization_codes + columnName: client_id + newDataType: VARCHAR(255) + + #pushed_authorization_requests + - modifyDataType: + tableName: pushed_authorization_requests + columnName: client + newDataType: VARCHAR(255) + + #ciba_auth_requests + - modifyDataType: + tableName: ciba_auth_requests + columnName: client + newDataType: VARCHAR(255) + + - changeSet: + id: 4.2.27-change-client-column-size-recreate-indexes # recreating indexes for MS SQL SERVER + author: GraviteeSource Team + dbms: mssql + changes: + # device + - createIndex: + columns: + - column: + name: reference_id + - column: + name: reference_type + - column: + name: client + - column: + name: user_id + indexName: idx_devices_domain_client_user + tableName: devices + unique: false + # scope_approvals + - createIndex: + columns: + - column: + name: domain + - column: + name: client_id + - column: + name: user_id + - column: + name: scope + indexName: idx_scope_approvals_domain_client_user_scope + tableName: scope_approvals + unique: true + + #access_tokens + - createIndex: + columns: + - column: + name: client + indexName: idx_access_tokens_client + tableName: access_tokens + unique: false + - createIndex: + columns: + - column: + name: domain + - column: + name: client + - column: + name: subject + indexName: idx_access_tokens_domain_client_subject + tableName: access_tokens + unique: false + + #refresh_tokens + - createIndex: + columns: + - column: + name: client + indexName: idx_refresh_tokens_client + tableName: refresh_tokens + unique: false + - createIndex: + columns: + - column: + name: domain + - column: + name: client + - column: + name: subject + indexName: idx_refresh_tokens_domain_client_subject + tableName: refresh_tokens + unique: false diff --git a/gravitee-am-repository/gravitee-am-repository-jdbc/src/main/resources/liquibase/changelogs/v4_5_5/4.5.5-scope-approval-index.yml b/gravitee-am-repository/gravitee-am-repository-jdbc/src/main/resources/liquibase/changelogs/v4_5_5/4.5.5-scope-approval-index.yml new file mode 100644 index 00000000000..ea6b38ffec5 --- /dev/null +++ b/gravitee-am-repository/gravitee-am-repository-jdbc/src/main/resources/liquibase/changelogs/v4_5_5/4.5.5-scope-approval-index.yml @@ -0,0 +1,31 @@ +# Recreate index for scope approval if not exit. +databaseChangeLog: + - changeSet: + id: 4.5.5-scope-approval-index + author: GraviteeSource Team + dbms: mssql + onError: MARK_RAN + preConditions: + - onFail: MARK_RAN + - not: + - indexExists: + tableName: scope_approvals + indexName: idx_scope_approvals_domain_client_user_id_extid_scope + changes: + - createIndex: + columns: + - column: + name: domain + - column: + name: client_id + - column: + name: user_id + - column: + name: user_source + - column: + name: user_external_id + - column: + name: scope + indexName: idx_scope_approvals_domain_client_user_id_extid_scope + tableName: scope_approvals + unique: false diff --git a/gravitee-am-repository/gravitee-am-repository-jdbc/src/main/resources/liquibase/master.yml b/gravitee-am-repository/gravitee-am-repository-jdbc/src/main/resources/liquibase/master.yml index 4442aa99e09..fc310386dbe 100644 --- a/gravitee-am-repository/gravitee-am-repository-jdbc/src/main/resources/liquibase/master.yml +++ b/gravitee-am-repository/gravitee-am-repository-jdbc/src/main/resources/liquibase/master.yml @@ -121,6 +121,8 @@ databaseChangeLog: - file: liquibase/changelogs/v4_1_0/4.1.35-update-web-credential-index.yml - include: - file: liquibase/changelogs/v4_2_0/4.2.0-update-applications-table.yml + - include: + - file: liquibase/changelogs/v4_2_27/4.2.27-change-client-column-size.yml - include: - file: liquibase/changelogs/v4_3_0/4.3.0-license-notification-permission.yml - include: @@ -151,3 +153,5 @@ databaseChangeLog: - file: liquibase/changelogs/v4_5_0/4.5.0-scope-approval-external-user-id.yml - include: - file: liquibase/changelogs/v4_5_0/4.5.0-add-node-monitoring-index.yml + - include: + - file: liquibase/changelogs/v4_5_5/4.5.5-scope-approval-index.yml \ No newline at end of file diff --git a/gravitee-am-repository/gravitee-am-repository-tests/src/test/java/io/gravitee/am/repository/gateway/api/ScopeApprovalRepositoryTest.java b/gravitee-am-repository/gravitee-am-repository-tests/src/test/java/io/gravitee/am/repository/gateway/api/ScopeApprovalRepositoryTest.java index 92c806ed1f5..f33d27e2276 100644 --- a/gravitee-am-repository/gravitee-am-repository-tests/src/test/java/io/gravitee/am/repository/gateway/api/ScopeApprovalRepositoryTest.java +++ b/gravitee-am-repository/gravitee-am-repository-tests/src/test/java/io/gravitee/am/repository/gateway/api/ScopeApprovalRepositoryTest.java @@ -18,6 +18,7 @@ import io.gravitee.am.model.UserId; import io.gravitee.am.model.oauth2.ScopeApproval; import io.gravitee.am.repository.gateway.AbstractGatewayTest; +import io.reactivex.rxjava3.observers.TestObserver; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -95,6 +96,16 @@ public void shouldFindNothingByNullId() { .isInstanceOf(IllegalArgumentException.class); } + @Test + public void shouldCreateWithLongClientName(){ + ScopeApproval scopeApproval = basicApproval(); + scopeApproval.setClientId("very-long-client-very-long-client-very-long-client-very-long-client-very-long-client-very-long-client"); + TestObserver testObserver = repository.create(scopeApproval).test(); + testObserver.awaitDone(10, TimeUnit.SECONDS); + testObserver.assertComplete(); + testObserver.assertNoErrors(); + } + // common test data private void givenStandardTestApprovalsExist() { List.of(basicApprovalFor(fullUserId), diff --git a/gravitee-am-repository/gravitee-am-repository-tests/src/test/java/io/gravitee/am/repository/management/api/DeviceRepositoryTest.java b/gravitee-am-repository/gravitee-am-repository-tests/src/test/java/io/gravitee/am/repository/management/api/DeviceRepositoryTest.java index f45aa554825..5a1ad580876 100644 --- a/gravitee-am-repository/gravitee-am-repository-tests/src/test/java/io/gravitee/am/repository/management/api/DeviceRepositoryTest.java +++ b/gravitee-am-repository/gravitee-am-repository-tests/src/test/java/io/gravitee/am/repository/management/api/DeviceRepositoryTest.java @@ -265,7 +265,16 @@ public void shouldFindByReferenceAndUserId() { .ignoreElement() .andThen(repository.findByReferenceAndUser(ReferenceType.DOMAIN, testDomain, testUser)) .test().awaitDone(5, TimeUnit.SECONDS) - .assertComplete() - ; + .assertComplete(); + } + + @Test + public void createWithLongClient(){ + Device device = buildDevice(); + device.setClient("very-long-client-very-long-client-very-long-client-very-long-client-very-long-client-very-long-client"); + TestObserver deviceTestObserver = repository.create(device).test().awaitDone(10, TimeUnit.SECONDS); + deviceTestObserver.awaitDone(10, TimeUnit.SECONDS); + deviceTestObserver.assertComplete(); + deviceTestObserver.assertNoErrors(); } } diff --git a/gravitee-am-repository/gravitee-am-repository-tests/src/test/java/io/gravitee/am/repository/oauth2/api/AccessTokenRepositoryTest.java b/gravitee-am-repository/gravitee-am-repository-tests/src/test/java/io/gravitee/am/repository/oauth2/api/AccessTokenRepositoryTest.java index 67cca1e9366..c9c85941031 100644 --- a/gravitee-am-repository/gravitee-am-repository-tests/src/test/java/io/gravitee/am/repository/oauth2/api/AccessTokenRepositoryTest.java +++ b/gravitee-am-repository/gravitee-am-repository-tests/src/test/java/io/gravitee/am/repository/oauth2/api/AccessTokenRepositoryTest.java @@ -65,6 +65,22 @@ public void shouldFindToken() { observer.assertNoErrors(); } + @Test + public void shouldCreateWithLongClientId() { + AccessToken token = new AccessToken(); + token.setId(RandomString.generate()); + token.setToken("my-token"); + token.setClient("very-long-client-very-long-client-very-long-client-very-long-client-very-long-client-very-long-client"); + + TestObserver observer = accessTokenRepository + .create(token).test(); + + observer.awaitDone(10, TimeUnit.SECONDS); + + observer.assertComplete(); + observer.assertNoErrors(); + } + @Test public void shouldDeleteByToken() { AccessToken token = new AccessToken(); diff --git a/gravitee-am-repository/gravitee-am-repository-tests/src/test/java/io/gravitee/am/repository/oauth2/api/AuthorizationCodeRepositoryTest.java b/gravitee-am-repository/gravitee-am-repository-tests/src/test/java/io/gravitee/am/repository/oauth2/api/AuthorizationCodeRepositoryTest.java index 9db317b5170..da1b4380560 100644 --- a/gravitee-am-repository/gravitee-am-repository-tests/src/test/java/io/gravitee/am/repository/oauth2/api/AuthorizationCodeRepositoryTest.java +++ b/gravitee-am-repository/gravitee-am-repository-tests/src/test/java/io/gravitee/am/repository/oauth2/api/AuthorizationCodeRepositoryTest.java @@ -81,4 +81,19 @@ public void shouldRemoveCode() throws InterruptedException { deletionValidationObserver.assertNoValues(); } + @Test + public void shouldCreateWithLongClientId() { + AuthorizationCode authorizationCode = new AuthorizationCode(); + authorizationCode.setId("test"); + authorizationCode.setCode("test"); + authorizationCode.setClientId("very-long-client-very-long-client-very-long-client-very-long-client-very-long-client-very-long-client"); + + TestObserver observer = authorizationCodeRepository + .create(authorizationCode).test(); + + observer.awaitDone(10, TimeUnit.SECONDS); + observer.assertComplete(); + observer.assertNoErrors(); + } + } diff --git a/gravitee-am-repository/gravitee-am-repository-tests/src/test/java/io/gravitee/am/repository/oauth2/api/CibaAuthRequestRepositoryTest.java b/gravitee-am-repository/gravitee-am-repository-tests/src/test/java/io/gravitee/am/repository/oauth2/api/CibaAuthRequestRepositoryTest.java index d51061f6f83..255e5f00dd3 100644 --- a/gravitee-am-repository/gravitee-am-repository-tests/src/test/java/io/gravitee/am/repository/oauth2/api/CibaAuthRequestRepositoryTest.java +++ b/gravitee-am-repository/gravitee-am-repository-tests/src/test/java/io/gravitee/am/repository/oauth2/api/CibaAuthRequestRepositoryTest.java @@ -173,5 +173,18 @@ public void shouldDelete() { observer.assertNoErrors(); } + @Test + public void shouldCreateWithLongClientName() { + final String id = RandomString.generate(); + CibaAuthRequest authRequest = buildCibaAuthRequest(id); + authRequest.setClientId("very-long-client-very-long-client-very-long-client-very-long-client-very-long-client-very-long-client"); + + TestObserver observer = repository.create(authRequest).test(); + + observer.awaitDone(10, TimeUnit.SECONDS); + observer.assertComplete(); + observer.assertNoErrors(); + } + } diff --git a/gravitee-am-repository/gravitee-am-repository-tests/src/test/java/io/gravitee/am/repository/oauth2/api/PushedAuthorizationRequestRepositoryTest.java b/gravitee-am-repository/gravitee-am-repository-tests/src/test/java/io/gravitee/am/repository/oauth2/api/PushedAuthorizationRequestRepositoryTest.java index 41a324066de..f46b21fb457 100644 --- a/gravitee-am-repository/gravitee-am-repository-tests/src/test/java/io/gravitee/am/repository/oauth2/api/PushedAuthorizationRequestRepositoryTest.java +++ b/gravitee-am-repository/gravitee-am-repository-tests/src/test/java/io/gravitee/am/repository/oauth2/api/PushedAuthorizationRequestRepositoryTest.java @@ -92,5 +92,21 @@ public void shouldDelete() { observer.assertNoErrors(); } + @Test + public void shouldCreateWithLongClientName() { + PushedAuthorizationRequest par = new PushedAuthorizationRequest(); + final String id = RandomString.generate(); + par.setId(id); + par.setDomain("domain"); + par.setClient("very-long-client-very-long-client-very-long-client-very-long-client-very-long-client-very-long-client"); + final LinkedMultiValueMap parameters = new LinkedMultiValueMap<>(); + parameters.add("key", "value"); + par.setParameters(parameters); + + TestObserver observer = repository.create(par).test(); + observer.awaitDone(10, TimeUnit.SECONDS); + observer.assertComplete(); + observer.assertNoErrors(); + } } diff --git a/gravitee-am-repository/gravitee-am-repository-tests/src/test/java/io/gravitee/am/repository/oauth2/api/RefreshTokenRepositoryTest.java b/gravitee-am-repository/gravitee-am-repository-tests/src/test/java/io/gravitee/am/repository/oauth2/api/RefreshTokenRepositoryTest.java index 9377d51c14c..59b42441a79 100644 --- a/gravitee-am-repository/gravitee-am-repository-tests/src/test/java/io/gravitee/am/repository/oauth2/api/RefreshTokenRepositoryTest.java +++ b/gravitee-am-repository/gravitee-am-repository-tests/src/test/java/io/gravitee/am/repository/oauth2/api/RefreshTokenRepositoryTest.java @@ -135,4 +135,19 @@ public void shouldDeleteByDomainIdAndUserId() { assertNotNull(refreshTokenRepository.findByToken("my-token2").blockingGet()); } + @Test + public void shouldCreateWithLongClientId() { + RefreshToken token = new RefreshToken(); + token.setId(RandomString.generate()); + token.setToken("my-token"); + token.setClient("very-long-client-very-long-client-very-long-client-very-long-client-very-long-client-very-long-client"); + + TestObserver observer = refreshTokenRepository + .create(token).test(); + + observer.awaitDone(10, TimeUnit.SECONDS); + observer.assertComplete(); + observer.assertNoErrors(); + } + }