-
Notifications
You must be signed in to change notification settings - Fork 735
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/issue-1597-add-listCodeownersErrors
- Loading branch information
Showing
29 changed files
with
1,239 additions
and
9 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 was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package org.kohsuke.github; | ||
|
||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
import java.time.Instant; | ||
import java.util.Date; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import static com.github.npathai.hamcrestopt.OptionalMatchers.isPresent; | ||
import static org.hamcrest.Matchers.*; | ||
|
||
/** | ||
* The Class GHDeployKeyTest. | ||
* | ||
* @author Jonas van Vliet | ||
*/ | ||
public class GHDeployKeyTest extends AbstractGitHubWireMockTest { | ||
private static final String DEPLOY_KEY_TEST_REPO_NAME = "hub4j-test-org/GHDeployKeyTest"; | ||
private static final String ED_25519_READONLY = "DeployKey - ed25519 - readonly"; | ||
private static final String RSA_4096_READWRITE = "Deploykey - rsa4096 - readwrite"; | ||
private static final String KEY_CREATOR_USERNAME = "van-vliet"; | ||
|
||
/** | ||
* Test get deploymentkeys. | ||
* | ||
* @throws IOException | ||
* Signals that an I/O exception has occurred. | ||
*/ | ||
@Test | ||
public void testGetDeployKeys() throws IOException { | ||
final GHRepository repo = getRepository(); | ||
final List<GHDeployKey> deployKeys = repo.getDeployKeys(); | ||
assertThat("There should be 2 deploykeys in " + DEPLOY_KEY_TEST_REPO_NAME, deployKeys, hasSize(2)); | ||
|
||
Optional<GHDeployKey> ed25519Key = deployKeys.stream() | ||
.filter(key -> key.getTitle().equals(ED_25519_READONLY)) | ||
.findAny(); | ||
assertThat("The key exists", ed25519Key, isPresent()); | ||
assertThat("The key was created at the specified date", | ||
ed25519Key.get().getCreatedAt(), | ||
is(Date.from(Instant.parse("2023-02-08T10:00:15.00Z")))); | ||
assertThat("The key is created by " + KEY_CREATOR_USERNAME, | ||
ed25519Key.get().getAdded_by(), | ||
is(KEY_CREATOR_USERNAME)); | ||
assertThat("The key has a last_used value", | ||
ed25519Key.get().getLastUsedAt(), | ||
is(Date.from(Instant.parse("2023-02-08T10:02:11.00Z")))); | ||
assertThat("The key only has read access", ed25519Key.get().isRead_only(), is(true)); | ||
assertThat("Object has a toString()", ed25519Key.get().toString(), is(notNullValue())); | ||
|
||
Optional<GHDeployKey> rsa_4096Key = deployKeys.stream() | ||
.filter(key -> key.getTitle().equals(RSA_4096_READWRITE)) | ||
.findAny(); | ||
assertThat("The key exists", rsa_4096Key, isPresent()); | ||
assertThat("The key was created at the specified date", | ||
rsa_4096Key.get().getCreatedAt(), | ||
is(Date.from(Instant.parse("2023-01-26T14:12:12.00Z")))); | ||
assertThat("The key is created by " + KEY_CREATOR_USERNAME, | ||
rsa_4096Key.get().getAdded_by(), | ||
is(KEY_CREATOR_USERNAME)); | ||
assertThat("The key has never been used", rsa_4096Key.get().getLastUsedAt(), is(nullValue())); | ||
assertThat("The key only has read/write access", rsa_4096Key.get().isRead_only(), is(false)); | ||
} | ||
|
||
/** | ||
* Gets the repository. | ||
* | ||
* @return the repository | ||
* @throws IOException | ||
* Signals that an I/O exception has occurred. | ||
*/ | ||
protected GHRepository getRepository() throws IOException { | ||
return getRepository(gitHub); | ||
} | ||
|
||
private GHRepository getRepository(final GitHub gitHub) throws IOException { | ||
return gitHub.getRepository(DEPLOY_KEY_TEST_REPO_NAME); | ||
} | ||
} |
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 @@ | ||
package org.kohsuke.github; | ||
|
||
import org.junit.Test; | ||
|
||
/** | ||
* The Class GHPublicKeyTest. | ||
* | ||
* @author Jonas van Vliet | ||
*/ | ||
public class GHPublicKeyTest extends AbstractGitHubWireMockTest { | ||
|
||
private static final String TMP_KEY_NAME = "Temporary user key"; | ||
private static final String WIREMOCK_SSH_PUBLIC_KEY = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDepW2/BSVFM2AfuGGsvi+vjQzC0EBD3R+/7PNEvP0/nvTWxiC/tthfvvCJR6TKrsprCir5tiJFm73gX+K18W0RKYpkyg8H6d1eZu3q/JOiGvoDPeN8Oe9hOGeeexw1WOiz7ESPHzZYXI981evzHAzxxn8zibr2EryopVNsXyoenw=="; | ||
|
||
/** | ||
* Test adding a public key to the user | ||
* | ||
* @throws Exception | ||
* the exception | ||
*/ | ||
@Test | ||
public void testAddPublicKey() throws Exception { | ||
GHKey newPublicKey = null; | ||
try { | ||
GHMyself me = gitHub.getMyself(); | ||
newPublicKey = me.addPublicKey(TMP_KEY_NAME, WIREMOCK_SSH_PUBLIC_KEY); | ||
} finally { | ||
if (newPublicKey != null) { | ||
newPublicKey.delete(); | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.