Skip to content

Commit 3344530

Browse files
committed
Drop Nimbus. Fix manually recordings to be compliant with default JWK
1 parent 8585f3a commit 3344530

File tree

14 files changed

+150
-122
lines changed

14 files changed

+150
-122
lines changed

pom.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -600,12 +600,6 @@
600600
<version>2.0.3</version>
601601
<scope>test</scope>
602602
</dependency>
603-
<dependency>
604-
<groupId>com.nimbusds</groupId>
605-
<artifactId>nimbus-jose-jwt</artifactId>
606-
<version>9.5</version>
607-
<scope>test</scope>
608-
</dependency>
609603
</dependencies>
610604
<repositories>
611605
<repository>

src/main/java/org/kohsuke/github/GHAppInstallation.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ public GHAppCreateTokenBuilder createToken() {
374374
*
375375
* @return a GHMarketplaceAccountPlan instance
376376
* @throws IOException
377+
* it may throw an {@link IOException}
377378
* @see <a href=
378379
* "https://docs.github.com/en/rest/apps/marketplace?apiVersion=2022-11-28#get-a-subscription-plan-for-an-account">Get
379380
* a subscription plan for an account</a>

src/main/java/org/kohsuke/github/GHMarketplaceAccount.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public GHMarketplaceAccountType getType() {
8585
*
8686
* @return a GHMarketplaceListAccountBuilder instance
8787
* @throws IOException
88+
* in case of {@link IOException}
8889
* @see <a href=
8990
* "https://docs.github.com/en/rest/apps/marketplace?apiVersion=2022-11-28#get-a-subscription-plan-for-an-account">Get
9091
* a subscription plan for an account</a>

src/main/java/org/kohsuke/github/extras/authorization/JWTTokenProvider.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import io.jsonwebtoken.JwtBuilder;
44
import io.jsonwebtoken.Jwts;
55
import io.jsonwebtoken.SignatureAlgorithm;
6+
import io.jsonwebtoken.jackson.io.JacksonSerializer;
67
import org.kohsuke.github.authorization.AuthorizationProvider;
78

89
import java.io.File;
@@ -181,7 +182,7 @@ private String refreshJWT() {
181182
validUntil = expiration.minus(Duration.ofMinutes(2));
182183

183184
// Builds the JWT and serializes it to a compact, URL-safe string
184-
return builder.compact();
185+
return builder.serializeToJsonWith(new JacksonSerializer<>()).compact();
185186
}
186187

187188
Instant getIssuedAt(Instant now) {

src/test/java/org/kohsuke/github/AbstractGHAppInstallationTest.java

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package org.kohsuke.github;
22

3-
import com.nimbusds.jose.JOSEException;
4-
import com.nimbusds.jose.crypto.impl.RSAKeyUtils;
5-
import com.nimbusds.jose.jwk.RSAKey;
63
import io.jsonwebtoken.Jwts;
74
import org.apache.commons.io.IOUtils;
85
import org.kohsuke.github.authorization.AuthorizationProvider;
@@ -12,11 +9,11 @@
129
import java.io.IOException;
1310
import java.nio.charset.StandardCharsets;
1411
import java.nio.file.Files;
12+
import java.nio.file.Paths;
1513
import java.security.GeneralSecurityException;
1614
import java.security.KeyFactory;
1715
import java.security.PrivateKey;
1816
import java.security.spec.PKCS8EncodedKeySpec;
19-
import java.text.ParseException;
2017
import java.time.Instant;
2118
import java.time.temporal.ChronoUnit;
2219
import java.util.Base64;
@@ -31,7 +28,7 @@
3128
public class AbstractGHAppInstallationTest extends AbstractGitHubWireMockTest {
3229

3330
private static String ENV_GITHUB_APP_ID = "GITHUB_APP_ID";
34-
private static String ENV_GITHUB_APP_TOKEN = "GITHUB_APP_TOKEN";
31+
private static String ENV_GITHUB_APP_JWK_PATH = "GITHUB_APP_JWK_PATH";
3532
private static String ENV_GITHUB_APP_ORG = "GITHUB_APP_ORG";
3633
private static String ENV_GITHUB_APP_REPO = "GITHUB_APP_REPO";
3734

@@ -56,19 +53,12 @@ public class AbstractGHAppInstallationTest extends AbstractGitHubWireMockTest {
5653
*/
5754
protected AbstractGHAppInstallationTest() {
5855
String appId = System.getenv(ENV_GITHUB_APP_ID);
59-
String appToken = System.getenv(ENV_GITHUB_APP_TOKEN);
56+
String appJwkPath = System.getenv(ENV_GITHUB_APP_JWK_PATH);
6057
try {
61-
if (appId != null && appToken != null) {
62-
RSAKey rsaJWK;
63-
try {
64-
rsaJWK = RSAKey.parse(appToken);
65-
} catch (IllegalStateException | ParseException e) {
66-
throw new IllegalStateException("Issue parsing privateKey", e);
67-
}
68-
69-
jwtProvider1 = new JWTTokenProvider(appId, RSAKeyUtils.toRSAPrivateKey(rsaJWK));
70-
jwtProvider2 = new JWTTokenProvider(appId, RSAKeyUtils.toRSAPrivateKey(rsaJWK));
71-
jwtProvider3 = new JWTTokenProvider(appId, RSAKeyUtils.toRSAPrivateKey(rsaJWK));
58+
if (appId != null && appJwkPath != null) {
59+
jwtProvider1 = new JWTTokenProvider(appId, Paths.get(appJwkPath));
60+
jwtProvider2 = jwtProvider1;
61+
jwtProvider3 = jwtProvider1;
7262
} else {
7363
jwtProvider1 = new JWTTokenProvider(TEST_APP_ID_1,
7464
new File(this.getClass().getResource(PRIVATE_KEY_FILE_APP_1).getFile()));
@@ -79,7 +69,7 @@ protected AbstractGHAppInstallationTest() {
7969
new File(this.getClass().getResource(PRIVATE_KEY_FILE_APP_3).getFile()).toPath()),
8070
StandardCharsets.UTF_8));
8171
}
82-
} catch (GeneralSecurityException | IOException | JOSEException e) {
72+
} catch (GeneralSecurityException | IOException e) {
8373
throw new RuntimeException("These should never fail", e);
8474
}
8575
}

src/test/java/org/kohsuke/github/GHMarketplacePlanTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ static void testMarketplacePurchase(GHMarketplacePurchase marketplacePurchase) {
167167
if (marketplacePurchase.getPlan().getPriceModel() == GHMarketplacePriceModel.PER_UNIT)
168168
assertThat(marketplacePurchase.getUnitCount(), notNullValue());
169169
else
170-
assertThat(marketplacePurchase.getUnitCount(), Matchers.either(nullValue()).or(is(1L)));
170+
assertThat(marketplacePurchase.getUnitCount(), Matchers.anyOf(nullValue(), is(1L)));
171171

172172
}
173173

src/test/resources/org/kohsuke/github/GHAppInstallationTest/wiremock/testGetMarketplaceAccount/__files/app-1.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"id": 65550,
2+
"id": 83009,
33
"slug": "cleanthat",
44
"node_id": "MDM6QXBwNjU1NTA=",
55
"owner": {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
[
2+
{
3+
"id": 12131496,
4+
"account": {
5+
"login": "hub4j-test-org",
6+
"id": 7544739,
7+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
8+
"avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4",
9+
"gravatar_id": "",
10+
"url": "https://api.github.com/users/hub4j-test-org",
11+
"html_url": "https://github.com/hub4j-test-org",
12+
"followers_url": "https://api.github.com/users/hub4j-test-org/followers",
13+
"following_url": "https://api.github.com/users/hub4j-test-org/following{/other_user}",
14+
"gists_url": "https://api.github.com/users/hub4j-test-org/gists{/gist_id}",
15+
"starred_url": "https://api.github.com/users/hub4j-test-org/starred{/owner}{/repo}",
16+
"subscriptions_url": "https://api.github.com/users/hub4j-test-org/subscriptions",
17+
"organizations_url": "https://api.github.com/users/hub4j-test-org/orgs",
18+
"repos_url": "https://api.github.com/users/hub4j-test-org/repos",
19+
"events_url": "https://api.github.com/users/hub4j-test-org/events{/privacy}",
20+
"received_events_url": "https://api.github.com/users/hub4j-test-org/received_events",
21+
"type": "Organization",
22+
"site_admin": false
23+
},
24+
"repository_selection": "selected",
25+
"access_tokens_url": "https://api.github.com/app/installations/12131496/access_tokens",
26+
"repositories_url": "https://api.github.com/installation/repositories",
27+
"html_url": "https://github.com/organizations/hub4j-test-org/settings/installations/12131496",
28+
"app_id": 83009,
29+
"app_slug": "ghapi-test-app-2",
30+
"target_id": 7544739,
31+
"target_type": "Organization",
32+
"permissions": {},
33+
"events": [],
34+
"created_at": "2020-09-30T15:05:32.000Z",
35+
"updated_at": "2020-09-30T15:05:32.000Z",
36+
"single_file_name": null,
37+
"has_multiple_single_files": false,
38+
"single_file_paths": [],
39+
"suspended_by": null,
40+
"suspended_at": null
41+
}
42+
]

src/test/resources/org/kohsuke/github/GHAppInstallationTest/wiremock/testGetMarketplaceAccount/__files/marketplace_listing_accounts_34552197-3.json renamed to src/test/resources/org/kohsuke/github/GHAppInstallationTest/wiremock/testGetMarketplaceAccount/__files/marketplace_listing_accounts_7544739-3.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"url": "https://api.github.com/orgs/solven-eu",
33
"type": "Organization",
4-
"id": 34552197,
4+
"id": 7544739,
55
"login": "solven-eu",
66
"marketplace_pending_change": null,
77
"marketplace_purchase": {
@@ -32,5 +32,5 @@
3232
]
3333
}
3434
},
35-
"organization_billing_email": "accounting@m-itrust.com"
35+
"organization_billing_email": "accounting@toto.com"
3636
}

src/test/resources/org/kohsuke/github/GHAppInstallationTest/wiremock/testGetMarketplaceAccount/__files/repos_solven-eu_cleanthat_installation-2.json

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)