diff --git a/README.md b/README.md index ff6713ce..e97b9cbd 100644 --- a/README.md +++ b/README.md @@ -343,7 +343,7 @@ credentials: - gitlabPersonalAccessToken: scope: SYSTEM id: "i<3GitLab" - token: "XfsqZvVtAx5YCph5bq3r" # gitlab personal access token + token: "glpat-XfsqZvVtAx5YCph5bq3r" # gitlab personal access token unclassified: gitLabServers: diff --git a/src/main/java/io/jenkins/plugins/gitlabserverconfig/credentials/PersonalAccessTokenImpl.java b/src/main/java/io/jenkins/plugins/gitlabserverconfig/credentials/PersonalAccessTokenImpl.java index 646f38db..d68f228b 100644 --- a/src/main/java/io/jenkins/plugins/gitlabserverconfig/credentials/PersonalAccessTokenImpl.java +++ b/src/main/java/io/jenkins/plugins/gitlabserverconfig/credentials/PersonalAccessTokenImpl.java @@ -65,7 +65,7 @@ public Secret getToken() { @Symbol("gitlabPersonalAccessToken") public static class DescriptorImpl extends CredentialsDescriptor { - private static final int GITLAB_ACCESS_TOKEN_LENGTH = 20; + private static final int GITLAB_ACCESS_TOKEN_MINIMAL_LENGTH = 20; /** * {@inheritDoc} @@ -87,11 +87,11 @@ public String getDisplayName() { public FormValidation doCheckToken(@QueryParameter String value) { Secret secret = Secret.fromString(value); if (StringUtils.equals(value, secret.getPlainText())) { - if (value.length() != GITLAB_ACCESS_TOKEN_LENGTH) { + if (value.length() < GITLAB_ACCESS_TOKEN_MINIMAL_LENGTH) { return FormValidation .error(Messages.PersonalAccessTokenImpl_tokenWrongLength()); } - } else if (secret.getPlainText().length() != GITLAB_ACCESS_TOKEN_LENGTH) { + } else if (secret.getPlainText().length() < GITLAB_ACCESS_TOKEN_MINIMAL_LENGTH) { return FormValidation.error(Messages.PersonalAccessTokenImpl_tokenWrongLength()); } return FormValidation.ok(); diff --git a/src/main/resources/io/jenkins/plugins/gitlabserverconfig/credentials/Messages.properties b/src/main/resources/io/jenkins/plugins/gitlabserverconfig/credentials/Messages.properties index 6720dea6..2fcd55b6 100644 --- a/src/main/resources/io/jenkins/plugins/gitlabserverconfig/credentials/Messages.properties +++ b/src/main/resources/io/jenkins/plugins/gitlabserverconfig/credentials/Messages.properties @@ -1,3 +1,3 @@ PersonalAccessTokenImpl.displayName=GitLab Personal Access Token PersonalAccessTokenImpl.tokenRequired=Token required -PersonalAccessTokenImpl.tokenWrongLength=Token should be 20 characters long +PersonalAccessTokenImpl.tokenWrongLength=Token should be at least 20 characters long diff --git a/src/test/java/io/jenkins/plugins/gitlabserverconfig/casc/ConfigurationAsCodeTest.java b/src/test/java/io/jenkins/plugins/gitlabserverconfig/casc/ConfigurationAsCodeTest.java index 63c059f5..f09a5f45 100644 --- a/src/test/java/io/jenkins/plugins/gitlabserverconfig/casc/ConfigurationAsCodeTest.java +++ b/src/test/java/io/jenkins/plugins/gitlabserverconfig/casc/ConfigurationAsCodeTest.java @@ -47,8 +47,8 @@ public void should_support_configuration_as_code() { ); assertThat(credentials, hasSize(1)); final PersonalAccessTokenImpl credential = credentials.get(0); - assertThat(credential.getToken().getPlainText(), is("XfsqZvVtAx5YCph5bq3r")); - assertThat(credential.getToken().getEncryptedValue(), is(not("XfsqZvVtAx5YCph5bq3r"))); + assertThat(credential.getToken().getPlainText(), is("glpat-XfsqZvVtAx5YCph5bq3r")); + assertThat(credential.getToken().getEncryptedValue(), is(not("glpat-XfsqZvVtAx5YCph5bq3r"))); } @Test diff --git a/src/test/resources/io/jenkins/plugins/gitlabserverconfig/casc/configuration-as-code.yml b/src/test/resources/io/jenkins/plugins/gitlabserverconfig/casc/configuration-as-code.yml index ca2ebb97..9c37c139 100644 --- a/src/test/resources/io/jenkins/plugins/gitlabserverconfig/casc/configuration-as-code.yml +++ b/src/test/resources/io/jenkins/plugins/gitlabserverconfig/casc/configuration-as-code.yml @@ -5,7 +5,7 @@ credentials: - gitlabPersonalAccessToken: scope: SYSTEM id: "i<3GitLab" - token: "XfsqZvVtAx5YCph5bq3r" + token: "glpat-XfsqZvVtAx5YCph5bq3r" unclassified: gitLabServers: