-
Notifications
You must be signed in to change notification settings - Fork 736
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
Add ability to update a check run #980
Merged
Merged
Changes from 3 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
77 changes: 77 additions & 0 deletions
77
src/test/java/org/kohsuke/github/AbstractGHAppInstallationTest.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,77 @@ | ||
package org.kohsuke.github; | ||
|
||
import io.jsonwebtoken.Jwts; | ||
import org.apache.commons.io.IOUtils; | ||
|
||
import java.io.IOException; | ||
import java.security.KeyFactory; | ||
import java.security.PrivateKey; | ||
import java.security.spec.PKCS8EncodedKeySpec; | ||
import java.time.Instant; | ||
import java.time.temporal.ChronoUnit; | ||
import java.util.Base64; | ||
import java.util.Date; | ||
|
||
public class AbstractGHAppInstallationTest extends AbstractGitHubWireMockTest { | ||
|
||
private static String TEST_APP_ID_1 = "82994"; | ||
private static String TEST_APP_ID_2 = "83009"; | ||
private static String TEST_APP_ID_3 = "89368"; | ||
private static String PRIVATE_KEY_FILE_APP_1 = "/ghapi-test-app-1.private-key.pem"; | ||
private static String PRIVATE_KEY_FILE_APP_2 = "/ghapi-test-app-2.private-key.pem"; | ||
private static String PRIVATE_KEY_FILE_APP_3 = "/ghapi-test-app-3.private-key.pem"; | ||
|
||
private String createJwtToken(String keyFileResouceName, String appId) { | ||
try { | ||
String keyPEM = IOUtils.toString(this.getClass().getResource(keyFileResouceName), "US-ASCII") | ||
.replaceAll("(?m)^--.*", "") // remove comments from PEM to allow decoding | ||
.replaceAll("\\s", ""); | ||
|
||
PKCS8EncodedKeySpec keySpecPKCS8 = new PKCS8EncodedKeySpec(Base64.getDecoder().decode(keyPEM)); | ||
PrivateKey privateKey = KeyFactory.getInstance("RSA").generatePrivate(keySpecPKCS8); | ||
|
||
return Jwts.builder() | ||
.setIssuedAt(Date.from(Instant.now())) | ||
.setExpiration(Date.from(Instant.now().plus(5, ChronoUnit.MINUTES))) | ||
.setIssuer(appId) | ||
.signWith(privateKey) | ||
.compact(); | ||
} catch (Exception e) { | ||
throw new RuntimeException("Error creating JWT token.", e); | ||
} | ||
} | ||
|
||
private GHAppInstallation getAppInstallationWithToken(String jwtToken) throws IOException { | ||
GitHub gitHub = getGitHubBuilder().withJwtToken(jwtToken) | ||
.withEndpoint(mockGitHub.apiServer().baseUrl()) | ||
.build(); | ||
|
||
GHAppInstallation appInstallation = gitHub.getApp() | ||
.listInstallations() | ||
.toList() | ||
.stream() | ||
.filter(it -> it.getAccount().login.equals("hub4j-test-org")) | ||
.findFirst() | ||
.get(); | ||
|
||
appInstallation | ||
.setRoot(getGitHubBuilder().withAppInstallationToken(appInstallation.createToken().create().getToken()) | ||
.withEndpoint(mockGitHub.apiServer().baseUrl()) | ||
.build()); | ||
|
||
return appInstallation; | ||
} | ||
|
||
protected GHAppInstallation getAppInstallationWithTokenApp1() throws IOException { | ||
return getAppInstallationWithToken(createJwtToken(PRIVATE_KEY_FILE_APP_1, TEST_APP_ID_1)); | ||
} | ||
|
||
protected GHAppInstallation getAppInstallationWithTokenApp2() throws IOException { | ||
return getAppInstallationWithToken(createJwtToken(PRIVATE_KEY_FILE_APP_2, TEST_APP_ID_2)); | ||
} | ||
|
||
protected GHAppInstallation getAppInstallationWithTokenApp3() throws IOException { | ||
return getAppInstallationWithToken(createJwtToken(PRIVATE_KEY_FILE_APP_3, TEST_APP_ID_3)); | ||
} | ||
|
||
} |
65 changes: 2 additions & 63 deletions
65
src/test/java/org/kohsuke/github/GHAppInstallationTest.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
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,28 @@ | ||
-----BEGIN PRIVATE KEY----- | ||
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC4vG2q4zLRcQGe | ||
5Z4seo8LY2hROKkdy4LmA96TeCxwDd/bnFIIQGmWMZHVZkyruuLLArTt50/mJ4yC | ||
ggedRiw8CmH8s6iQmZQyRu+6gKVqm5KozQ2omniGAJU6KqZTbUUpvytpmmcWcoLU | ||
eMoLCJTScRK2rofbiSCFy1WwlyVe1b+nBNf2b9VG9bE461K47kgk1cI1/TqZ3QeI | ||
jc/0jV+w7qdTdCqD5A2FyFZa5mU6jj83bVyC0O0AlZlEnwHN58vvN3j7uljF6Mh0 | ||
sx+0xtRjmTncl7puUhpQBJrH/pIfjuY5MAefMaOAhXMZM3lZyh75URlO3vh1KKwQ | ||
EJcdCi+FAgMBAAECggEARDIDBf+DJf/iikbXgjHoFlsnCjyxaXdUJhctliDZvq/Q | ||
gKCPQ86La892t2FhUk/WIv0nz18BhsP4wcDAkNVzxOJMU936jw6yv3CiVKXi6pzt | ||
ofS4YxJLBaS3cdaGuetvib6xhvVhss6o70h7xWDwl1L4homdS3SuldV/F4ZkXEJI | ||
v5uyh0TFy44dSS01muJ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GvMei09uX1eVk= | ||
-----END PRIVATE KEY----- |
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.
Is there a reason you needed to update existing tests? Once the mocks are created they should continue to work so long as you are not actually changing the behavior of the existing APIs, which AFAICT you are not.
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.
It was to make it easier to update them for others by moving the tests to the test org and an app that others can use I believe (could be a separate pr)