-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Appu Goundan <[email protected]>
- Loading branch information
1 parent
5113aa2
commit 74be013
Showing
5 changed files
with
58 additions
and
26 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 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 |
---|---|---|
|
@@ -15,11 +15,9 @@ | |
*/ | ||
package dev.sigstore; | ||
|
||
import com.google.api.client.json.gson.GsonFactory; | ||
import com.google.api.client.json.webtoken.JsonWebSignature; | ||
import com.google.common.hash.Hashing; | ||
import dev.sigstore.bundle.Bundle; | ||
import dev.sigstore.oidc.client.GithubActionsOidcClient; | ||
import dev.sigstore.strings.StringMatcher; | ||
import dev.sigstore.testing.matchers.ByteArrayListMatcher; | ||
import dev.sigstore.testkit.annotations.EnabledIfOidcExists; | ||
import dev.sigstore.testkit.annotations.OidcProviderType; | ||
|
@@ -104,12 +102,15 @@ public void sign_digest() throws Exception { | |
|
||
@Test | ||
@EnabledIfOidcExists(provider = OidcProviderType.GITHUB) | ||
// this test will only pass on the github.com/sigstore/sigstore-java repository | ||
public void sign_failGithubOidcCheck() throws Exception { | ||
var signer = | ||
KeylessSigner.builder() | ||
.sigstorePublicDefaults() | ||
.allowedOidcIdentities(List.of(OidcIdentity.of("[email protected]", "goose.com"))) | ||
.allowedOidcIdentities( | ||
List.of( | ||
OidcIdentity.of( | ||
StringMatcher.string("[email protected]"), | ||
StringMatcher.string("goose.com")))) | ||
.build(); | ||
var ex = | ||
Assertions.assertThrows( | ||
|
@@ -127,20 +128,18 @@ public void sign_failGithubOidcCheck() throws Exception { | |
@EnabledIfOidcExists(provider = OidcProviderType.GITHUB) | ||
// this test will only pass on the github.com/sigstore/sigstore-java repository | ||
public void sign_passGithubOidcCheck() throws Exception { | ||
// silly way to get the right oidc identity to make sure our simple matcher works | ||
var jws = | ||
JsonWebSignature.parse( | ||
new GsonFactory(), | ||
GithubActionsOidcClient.builder().build().getIDToken(System.getenv()).getIdToken()); | ||
var expectedGithubSubject = jws.getPayload().getSubject(); | ||
var signer = | ||
KeylessSigner.builder() | ||
.sigstorePublicDefaults() | ||
.allowedOidcIdentities( | ||
List.of( | ||
OidcIdentity.of( | ||
expectedGithubSubject, "https://token.actions.githubusercontent.com"), | ||
OidcIdentity.of("[email protected]", "https://accounts.other.com"))) | ||
StringMatcher.regex( | ||
"https://github\\.com/sigstore/sigstore-java/\\.github/workflows/.*\\.yaml@.*"), | ||
StringMatcher.string("https://token.actions.githubusercontent.com")), | ||
OidcIdentity.of( | ||
StringMatcher.string("[email protected]"), | ||
StringMatcher.string("https://accounts.other.com")))) | ||
.build(); | ||
Assertions.assertDoesNotThrow( | ||
() -> | ||
|
34 changes: 34 additions & 0 deletions
34
sigstore-java/src/test/java/dev/sigstore/oidc/client/OidcTokenTest.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,34 @@ | ||
/* | ||
* Copyright 2024 The Sigstore Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package dev.sigstore.oidc.client; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class OidcTokenTest { | ||
|
||
@Test | ||
public void test_redacted() { | ||
var testToken = | ||
ImmutableOidcToken.builder() | ||
.issuer("issuer") | ||
.idToken("secret") | ||
.subjectAlternativeName("name") | ||
.build(); | ||
Assertions.assertEquals( | ||
"OidcToken{subjectAlternativeName=name, issuer=issuer}", testToken.toString()); | ||
} | ||
} |