Skip to content

Commit

Permalink
Allowing the gitlab token to be 20 characters or more (#233)
Browse files Browse the repository at this point in the history
Fixes #207

Co-authored-by: sebi <[email protected]>

Co-authored-by: sebi <[email protected]>
  • Loading branch information
jmini and sebi authored Aug 23, 2022
1 parent e2042bd commit 55fd814
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ credentials:
- gitlabPersonalAccessToken:
scope: SYSTEM
id: "i<3GitLab"
token: "XfsqZvVtAx5YCph5bq3r"
token: "glpat-XfsqZvVtAx5YCph5bq3r"

unclassified:
gitLabServers:
Expand Down

0 comments on commit 55fd814

Please sign in to comment.