-
-
Notifications
You must be signed in to change notification settings - Fork 469
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
✨ Fixed #JENKINS-44586. add support for managing credentials #264
Open
wei-lee
wants to merge
4
commits into
jenkinsci:master
Choose a base branch
from
feedhenry:JENKINS-44586-credential-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ job-dsl:1.41 | |
config-file-provider:2.10.0 | ||
testng-plugin:1.10 | ||
cloudbees-folder: 5.12 | ||
xcode-plugin: 2.0.0 |
123 changes: 123 additions & 0 deletions
123
.../src/test/java/com/offbytwo/jenkins/integration/NoExecutorStartedManageCredentialsIT.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,123 @@ | ||
package com.offbytwo.jenkins.integration; | ||
|
||
import com.offbytwo.jenkins.JenkinsServer; | ||
import com.offbytwo.jenkins.model.Plugin; | ||
import com.offbytwo.jenkins.model.credentials.*; | ||
import org.apache.commons.lang.RandomStringUtils; | ||
import org.testng.SkipException; | ||
import org.testng.annotations.Test; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.testng.Assert.*; | ||
|
||
@Test(groups = { Groups.NO_EXECUTOR_GROUP} ) | ||
public class NoExecutorStartedManageCredentialsIT extends AbstractJenkinsIntegrationCase { | ||
|
||
@Test | ||
public void credentialCRUDL() throws IOException { | ||
List<Plugin> plugins = jenkinsServer.getPluginManager().getPlugins(); | ||
Plugin credentialPlugin = jenkinsServer.findPluginWithName("credentials"); | ||
if (credentialPlugin == null) { | ||
throw new SkipException("No credentials plugin found. Skip Test"); | ||
} | ||
|
||
String pluginVersion = credentialPlugin.getVersion(); | ||
if (pluginVersion.startsWith("1.")) { | ||
runTest(jenkinsServer); | ||
|
||
//test CertificateCredential with upload cert file. The 2.x version may throw exceptions. | ||
CertificateCredential certificateCredential = new CertificateCredential(); | ||
certificateCredential.setId("certficateTest-" + RandomStringUtils.randomAlphanumeric(24)); | ||
certificateCredential.setCertificateSourceType(CertificateCredential.CERTIFICATE_SOURCE_TYPES.UPLOAD_CERT_FILE); | ||
certificateCredential.setCertificateContent("testcert".getBytes()); | ||
certificateCredential.setPassword("testpasssword"); | ||
|
||
credentialOperations(jenkinsServer, certificateCredential); | ||
|
||
} else { | ||
runTest(jenkinsServer); | ||
|
||
//test SecretTextCredential, this is v2 only | ||
SecretTextCredential secretText = new SecretTextCredential(); | ||
secretText.setId("secrettextcredentialTest-" + RandomStringUtils.randomAlphanumeric(24)); | ||
secretText.setSecret("testsecrettext"); | ||
|
||
credentialOperations(jenkinsServer, secretText); | ||
} | ||
} | ||
|
||
private void runTest(JenkinsServer jenkinsServer) throws IOException { | ||
String testUsername = "testusername"; | ||
String testPassword = "testpassword"; | ||
String credentialDescription = "testDescription"; | ||
//test UsernamePasswordCredential | ||
UsernamePasswordCredential testUPCredential = new UsernamePasswordCredential(); | ||
testUPCredential.setId("usernamepasswordcredentialTest-" + RandomStringUtils.randomAlphanumeric(24)); | ||
testUPCredential.setUsername(testUsername); | ||
testUPCredential.setPassword(testPassword); | ||
testUPCredential.setDescription(credentialDescription); | ||
|
||
credentialOperations(jenkinsServer, testUPCredential); | ||
|
||
//test SSHKeyCredential | ||
SSHKeyCredential sshCredential = new SSHKeyCredential(); | ||
sshCredential.setId("sshusercredentialTest-" + RandomStringUtils.randomAlphanumeric(24)); | ||
sshCredential.setUsername(testUsername); | ||
sshCredential.setPassphrase(testPassword); | ||
sshCredential.setPrivateKeyType(SSHKeyCredential.PRIVATE_KEY_TYPES.DIRECT_ENTRY); | ||
sshCredential.setPrivateKeyValue("testPrivateKeyContent"); | ||
|
||
credentialOperations(jenkinsServer, sshCredential); | ||
|
||
//test certificate credential | ||
CertificateCredential certificateCredential = new CertificateCredential(); | ||
certificateCredential.setId("certficateTest-" + RandomStringUtils.randomAlphanumeric(24)); | ||
certificateCredential.setCertificateSourceType(CertificateCredential.CERTIFICATE_SOURCE_TYPES.FILE_ON_MASTER); | ||
certificateCredential.setCertificatePath("/tmp/test"); | ||
certificateCredential.setPassword("testpasssword"); | ||
|
||
credentialOperations(jenkinsServer, certificateCredential); | ||
|
||
//test AppleDeveloperProfileCredential | ||
AppleDeveloperProfileCredential appleDevProfile = new AppleDeveloperProfileCredential(); | ||
appleDevProfile.setId("appleProfileTest-" + RandomStringUtils.randomAlphanumeric(24)); | ||
appleDevProfile.setPassword(testPassword); | ||
appleDevProfile.setDeveloperProfileContent("testprofile".getBytes()); | ||
|
||
credentialOperations(jenkinsServer, appleDevProfile); | ||
} | ||
|
||
private void credentialOperations(JenkinsServer jenkinsServer, Credential credential) throws IOException { | ||
//create the credential | ||
String credentialId = credential.getId(); | ||
jenkinsServer.createCredential(credential, false); | ||
|
||
//check if has been created by listing | ||
Map<String, Credential> credentials = jenkinsServer.listCredentials(); | ||
Credential found = credentials.get(credentialId); | ||
assertNotNull(found); | ||
assertEquals(credential.getTypeName(), found.getTypeName()); | ||
|
||
//compare fields | ||
assertEquals(credentialId, found.getId()); | ||
assertNotNull(found.getDisplayName()); | ||
|
||
//update the credential | ||
String updateDescription = "updatedDescription"; | ||
credential.setDescription(updateDescription); | ||
jenkinsServer.updateCredential(credentialId, credential, false); | ||
|
||
//verify it is updated | ||
credentials = jenkinsServer.listCredentials(); | ||
found = credentials.get(credentialId); | ||
assertEquals(updateDescription, found.getDescription()); | ||
|
||
//delete the credential | ||
jenkinsServer.deleteCredential(credentialId, false); | ||
credentials = jenkinsServer.listCredentials(); | ||
assertFalse(credentials.containsKey(credentialId)); | ||
} | ||
} |
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
25 changes: 25 additions & 0 deletions
25
jenkins-client/src/main/java/com/offbytwo/jenkins/client/FormBinaryField.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,25 @@ | ||
package com.offbytwo.jenkins.client; | ||
|
||
public class FormBinaryField { | ||
private String fileName; | ||
private String contentType; | ||
private byte[] content; | ||
|
||
public FormBinaryField(String fileName, String contentType, byte[] content) { | ||
this.fileName = fileName; | ||
this.contentType = contentType; | ||
this.content = content; | ||
} | ||
|
||
public String getFileName() { | ||
return fileName; | ||
} | ||
|
||
public String getContentType() { | ||
return contentType; | ||
} | ||
|
||
public byte[] getContent() { | ||
return content; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this not be an
or
instead of anand
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aidenkeating not really sure TBH. I didn't write this test. Just update the name of the test as I added a new plugin