-
Notifications
You must be signed in to change notification settings - Fork 8
JsonPatch test success #6
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
Open
dabloem
wants to merge
1
commit into
apache:rmannibucau/json-patch-jwt-payload
Choose a base branch
from
dabloem:rmannibucau/json-patch-jwt-payload
base: rmannibucau/json-patch-jwt-payload
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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 hidden or 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 hidden or 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
68 changes: 68 additions & 0 deletions
68
src/test/java/org/apache/geronimo/microprofile/impl/jwtauth/tck/jaxrs/JsonPatchTest.java
This file contains hidden or 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,68 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You 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 org.apache.geronimo.microprofile.impl.jwtauth.tck.jaxrs; | ||
|
|
||
| import org.eclipse.microprofile.jwt.tck.container.jaxrs.TCKApplication; | ||
| import org.eclipse.microprofile.jwt.tck.util.TokenUtils; | ||
| import org.jboss.arquillian.container.test.api.Deployment; | ||
| import org.jboss.arquillian.test.api.ArquillianResource; | ||
| import org.jboss.arquillian.testng.Arquillian; | ||
| import org.jboss.shrinkwrap.api.Archive; | ||
| import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
| import org.jboss.shrinkwrap.api.exporter.ZipExporter; | ||
| import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
| import org.testng.annotations.Test; | ||
|
|
||
| import javax.json.Json; | ||
| import javax.ws.rs.client.Client; | ||
| import javax.ws.rs.client.ClientBuilder; | ||
| import javax.ws.rs.core.Cookie; | ||
| import java.io.File; | ||
| import java.net.URL; | ||
|
|
||
| import static javax.ws.rs.core.MediaType.TEXT_PLAIN_TYPE; | ||
| import static org.testng.Assert.assertEquals; | ||
|
|
||
| // NOTE: reuses tck resources and token generation | ||
| public class JsonPatchTest extends Arquillian { | ||
| @Deployment(testable = false) | ||
| public static Archive<?> war() { | ||
| System.setProperty("geronimo.jwt-auth.jwt.payload.patch.default", "[ { \"op\": \"copy\", \"from\":\"/resource_access/service-C/groups\", \"path\": \"/groups\" } ]"); | ||
| return ShrinkWrap.create(WebArchive.class, JsonPatchTest.class.getSimpleName() + ".war") | ||
| .addClasses(TCKApplication.class, PassthroughEndpoint.class) | ||
| .addAsResource(JsonPatchTest.class.getResource("/publicKey.pem"), "/publicKey.pem"); | ||
| } | ||
|
|
||
| @ArquillianResource | ||
| private URL base; | ||
|
|
||
| @Test | ||
| public void test() throws Exception { | ||
| final Client client = ClientBuilder.newClient(); | ||
| try { | ||
| final String token = TokenUtils.generateTokenString("/Token2.json"); | ||
| final String serverToken = client.target(base.toExternalForm()) | ||
| .path("jsonpatch") | ||
| .request(TEXT_PLAIN_TYPE) | ||
| .cookie(new Cookie("Bearer", token)) | ||
| .get(String.class); | ||
| assertEquals(serverToken, token); | ||
| } finally { | ||
| client.close(); | ||
| } | ||
| } | ||
| } | ||
41 changes: 41 additions & 0 deletions
41
...st/java/org/apache/geronimo/microprofile/impl/jwtauth/tck/jaxrs/RolesAllowedEndpoint.java
This file contains hidden or 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,41 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You 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 org.apache.geronimo.microprofile.impl.jwtauth.tck.jaxrs; | ||
|
|
||
| import org.eclipse.microprofile.jwt.JsonWebToken; | ||
|
|
||
| import javax.annotation.security.RolesAllowed; | ||
| import javax.enterprise.context.ApplicationScoped; | ||
| import javax.inject.Inject; | ||
| import javax.ws.rs.GET; | ||
| import javax.ws.rs.Path; | ||
| import javax.ws.rs.Produces; | ||
| import javax.ws.rs.core.MediaType; | ||
|
|
||
| @Path("jsonpatch") | ||
| @ApplicationScoped | ||
| public class RolesAllowedEndpoint { | ||
| @Inject | ||
| private JsonWebToken token; | ||
|
|
||
| @GET | ||
| @Produces(MediaType.TEXT_PLAIN) | ||
| @RolesAllowed("groupC") | ||
| public String passthrough() { | ||
| return token.getRawToken(); | ||
| } | ||
| } |
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.
Can you use microprofile properties as a webapp asset instead? Goal is to have each test able to run in the same suite. TCK have a bug about it but we shouldnt prevent ourself to do it IMHO.
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.
sure, I try.
btw, you agree, that the defaultPatch is always used when no mapping is found (regardless off default kid value)?
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.
If kid is not in the mapping yes.
That said wonder if we shoulf support "none" value in the mapping to ease skipping that.
Wdyt?
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.
I don't see any real benefit in a 'none' value currently.
btw, I couldn't manage to get microprofile-config.properties to work. Either the tck tests fail or the projects tests fail when I add/remove a mp-config impl.
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.
If we dont support none then we only use default if kid is not set, not in all other cases to respect mapping config.
Not configured in mapping means "none" in this case.
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.
currently, the patch.mapping has higher priority then patch.default. So, if no patch.mapping is found then always apply the default jsonpatch if defined (regardless of geronimo.jwt-auth.jwt.header.kid.default is set, or not). This seems fine by me.
What is your use case, to be sure I understand you correctly.
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.
This one ;).
Point is that if you want default to be used if there is no mapping there is the need of a "noop" mapping (skipping an empty jsonpatch array for perf) so i proposed none.