| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -86,7 +86,7 @@ public class JwtCredentials extends Credentials implements JwtProvider { | |||
| 86 | 86 | ||
| 87 | 87 | private JwtCredentials(Builder builder) { | |
| 88 | 88 | this.privateKey = Preconditions.checkNotNull(builder.getPrivateKey()); | |
| 89 | - this.privateKeyId = Preconditions.checkNotNull(builder.getPrivateKeyId()); | ||
| 89 | + this.privateKeyId = builder.getPrivateKeyId(); | ||
| 90 | 90 | this.jwtClaims = Preconditions.checkNotNull(builder.getJwtClaims()); | |
| 91 | 91 | Preconditions.checkState(jwtClaims.isComplete(), JWT_INCOMPLETE_ERROR_MESSAGE); | |
| 92 | 92 | this.lifeSpanSeconds = Preconditions.checkNotNull(builder.getLifeSpanSeconds()); | |
@@ -220,7 +220,7 @@ public PrivateKey getPrivateKey() { | |||
| 220 | 220 | } | |
| 221 | 221 | ||
| 222 | 222 | public Builder setPrivateKeyId(String privateKeyId) { | |
| 223 | - this.privateKeyId = Preconditions.checkNotNull(privateKeyId); | ||
| 223 | + this.privateKeyId = privateKeyId; | ||
| 224 | 224 | return this; | |
| 225 | 225 | } | |
| 226 | 226 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -114,22 +114,6 @@ public void builder_requiresPrivateKey() { | |||
| 114 | 114 | } | |
| 115 | 115 | } | |
| 116 | 116 | ||
| 117 | - @Test | ||
| 118 | - public void builder_requiresPrivateKeyId() { | ||
| 119 | - try { | ||
| 120 | - JwtClaims claims = | ||
| 121 | - JwtClaims.newBuilder() | ||
| 122 | - .setAudience("some-audience") | ||
| 123 | - .setIssuer("some-issuer") | ||
| 124 | - .setSubject("some-subject") | ||
| 125 | - .build(); | ||
| 126 | - JwtCredentials.newBuilder().setJwtClaims(claims).setPrivateKey(getPrivateKey()).build(); | ||
| 127 | - fail("Should throw exception"); | ||
| 128 | - } catch (NullPointerException ex) { | ||
| 129 | - // expected | ||
| 130 | - } | ||
| 131 | - } | ||
| 132 | - | ||
| 133 | 117 | @Test | |
| 134 | 118 | public void builder_requiresClaims() { | |
| 135 | 119 | try { | |
@@ -248,6 +232,40 @@ public void getRequestMetadata_withAdditionalClaims_hasJwtAccess() throws IOExce | |||
| 248 | 232 | Collections.singletonMap("foo", "bar")); | |
| 249 | 233 | } | |
| 250 | 234 | ||
| 235 | + @Test | ||
| 236 | + public void privateKeyIdNull() throws IOException { | ||
| 237 | + JwtClaims claims = | ||
| 238 | + JwtClaims.newBuilder() | ||
| 239 | + .setAudience("some-audience") | ||
| 240 | + .setIssuer("some-issuer") | ||
| 241 | + .setSubject("some-subject") | ||
| 242 | + .build(); | ||
| 243 | + JwtCredentials credentials = | ||
| 244 | + JwtCredentials.newBuilder() | ||
| 245 | + .setJwtClaims(claims) | ||
| 246 | + .setPrivateKey(getPrivateKey()) | ||
| 247 | + .setPrivateKeyId(null) | ||
| 248 | + .build(); | ||
| 249 | + | ||
| 250 | + Map<String, List<String>> metadata = credentials.getRequestMetadata(); | ||
| 251 | + verifyJwtAccess(metadata, "some-audience", "some-issuer", "some-subject", null); | ||
| 252 | + } | ||
| 253 | + | ||
| 254 | + @Test | ||
| 255 | + public void privateKeyIdNotSpecified() throws IOException { | ||
| 256 | + JwtClaims claims = | ||
| 257 | + JwtClaims.newBuilder() | ||
| 258 | + .setAudience("some-audience") | ||
| 259 | + .setIssuer("some-issuer") | ||
| 260 | + .setSubject("some-subject") | ||
| 261 | + .build(); | ||
| 262 | + JwtCredentials credentials = | ||
| 263 | + JwtCredentials.newBuilder().setJwtClaims(claims).setPrivateKey(getPrivateKey()).build(); | ||
| 264 | + | ||
| 265 | + Map<String, List<String>> metadata = credentials.getRequestMetadata(); | ||
| 266 | + verifyJwtAccess(metadata, "some-audience", "some-issuer", "some-subject", null); | ||
| 267 | + } | ||
| 268 | + | ||
| 251 | 269 | private void verifyJwtAccess( | |
| 252 | 270 | Map<String, List<String>> metadata, | |
| 253 | 271 | String expectedAudience, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments