-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SONAR-6949 Increase crypted password size
- Loading branch information
Showing
12 changed files
with
233 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...gration/src/main/java/org/sonar/server/platform/db/migration/version/v72/DbVersion72.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* SonarQube | ||
* Copyright (C) 2009-2018 SonarSource SA | ||
* mailto:info AT sonarsource DOT com | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
package org.sonar.server.platform.db.migration.version.v72; | ||
|
||
import org.sonar.server.platform.db.migration.step.MigrationStepRegistry; | ||
import org.sonar.server.platform.db.migration.version.DbVersion; | ||
|
||
public class DbVersion72 implements DbVersion { | ||
|
||
@Override | ||
public void addSteps(MigrationStepRegistry registry) { | ||
registry | ||
.add(2100, "Increase size of CRYPTED_PASSWORD", IncreaseCryptedPasswordSize.class) | ||
; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
.../java/org/sonar/server/platform/db/migration/version/v72/IncreaseCryptedPasswordSize.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* SonarQube | ||
* Copyright (C) 2009-2018 SonarSource SA | ||
* mailto:info AT sonarsource DOT com | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
package org.sonar.server.platform.db.migration.version.v72; | ||
|
||
import java.sql.SQLException; | ||
import org.sonar.db.Database; | ||
import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder; | ||
import org.sonar.server.platform.db.migration.step.DdlChange; | ||
|
||
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder; | ||
|
||
public class IncreaseCryptedPasswordSize extends DdlChange { | ||
private static final String TABLE_NAME = "users"; | ||
|
||
public IncreaseCryptedPasswordSize(Database db) { | ||
super(db); | ||
} | ||
|
||
@Override | ||
public void execute(Context context) throws SQLException { | ||
context.execute(new AlterColumnsBuilder(getDialect(), TABLE_NAME) | ||
.updateColumn(newVarcharColumnDefBuilder() | ||
.setColumnName("crypted_password") | ||
.setLimit(100) | ||
.build()) | ||
.build()); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...ration/src/main/java/org/sonar/server/platform/db/migration/version/v72/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* SonarQube | ||
* Copyright (C) 2009-2018 SonarSource SA | ||
* mailto:info AT sonarsource DOT com | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
@ParametersAreNonnullByDefault | ||
package org.sonar.server.platform.db.migration.version.v72; | ||
|
||
import javax.annotation.ParametersAreNonnullByDefault; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...ion/src/test/java/org/sonar/server/platform/db/migration/version/v72/DbVersion72Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* SonarQube | ||
* Copyright (C) 2009-2018 SonarSource SA | ||
* mailto:info AT sonarsource DOT com | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
package org.sonar.server.platform.db.migration.version.v72; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.sonar.server.platform.db.migration.version.DbVersionTestUtils.verifyMigrationCount; | ||
import static org.sonar.server.platform.db.migration.version.DbVersionTestUtils.verifyMinimumMigrationNumber; | ||
|
||
public class DbVersion72Test { | ||
private DbVersion72 underTest = new DbVersion72(); | ||
|
||
@Test | ||
public void migrationNumber_starts_at_2100() { | ||
verifyMinimumMigrationNumber(underTest, 2100); | ||
} | ||
|
||
@Test | ||
public void verify_migration_count() { | ||
verifyMigrationCount(underTest, 1); | ||
} | ||
|
||
} |
63 changes: 63 additions & 0 deletions
63
...a/org/sonar/server/platform/db/migration/version/v72/IncreaseCryptedPasswordSizeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.sonar.server.platform.db.migration.version.v72;/* | ||
* SonarQube | ||
* Copyright (C) 2009-2018 SonarSource SA | ||
* mailto:info AT sonarsource DOT com | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
import java.sql.SQLException; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
import org.mindrot.jbcrypt.BCrypt; | ||
import org.sonar.db.CoreDbTester; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class IncreaseCryptedPasswordSizeTest { | ||
private static final String TABLE_NAME = "users"; | ||
|
||
@Rule | ||
public CoreDbTester db = CoreDbTester.createForSchema(IncreaseCryptedPasswordSizeTest.class, "users.sql"); | ||
@Rule | ||
public ExpectedException expectedException = ExpectedException.none(); | ||
|
||
private IncreaseCryptedPasswordSize underTest = new IncreaseCryptedPasswordSize(db.database()); | ||
|
||
@Test | ||
public void cannot_insert_crypted_password() { | ||
expectedException.expect(IllegalStateException.class); | ||
|
||
insertRow(); | ||
} | ||
|
||
@Test | ||
public void can_insert_crypted_password_after_execute() throws SQLException { | ||
underTest.execute(); | ||
assertThat(db.countRowsOfTable(TABLE_NAME)).isEqualTo(0); | ||
insertRow(); | ||
assertThat(db.countRowsOfTable(TABLE_NAME)).isEqualTo(1); | ||
} | ||
|
||
private void insertRow() { | ||
db.executeInsert( | ||
"USERS", | ||
"CRYPTED_PASSWORD", BCrypt.hashpw("a", BCrypt.gensalt()), | ||
"IS_ROOT", false, | ||
"ONBOARDED", false); | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
.../sonar/server/platform/db/migration/version/v72/IncreaseCryptedPasswordSizeTest/users.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
CREATE TABLE "USERS" ( | ||
"ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), | ||
"LOGIN" VARCHAR(255), | ||
"NAME" VARCHAR(200), | ||
"EMAIL" VARCHAR(100), | ||
"CRYPTED_PASSWORD" VARCHAR(40), | ||
"SALT" VARCHAR(40), | ||
"ACTIVE" BOOLEAN DEFAULT TRUE, | ||
"SCM_ACCOUNTS" VARCHAR(4000), | ||
"EXTERNAL_IDENTITY" VARCHAR(255), | ||
"EXTERNAL_IDENTITY_PROVIDER" VARCHAR(100), | ||
"IS_ROOT" BOOLEAN NOT NULL, | ||
"USER_LOCAL" BOOLEAN, | ||
"ONBOARDED" BOOLEAN NOT NULL, | ||
"CREATED_AT" BIGINT, | ||
"UPDATED_AT" BIGINT, | ||
"HOMEPAGE_TYPE" VARCHAR(40), | ||
"HOMEPAGE_PARAMETER" VARCHAR(40) | ||
); | ||
CREATE UNIQUE INDEX "USERS_LOGIN" ON "USERS" ("LOGIN"); | ||
CREATE INDEX "USERS_UPDATED_AT" ON "USERS" ("UPDATED_AT"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters