[
https://issues.apache.org/jira/browse/KNOX-2646?focusedWorklogId=641152&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-641152
]
ASF GitHub Bot logged work on KNOX-2646:
----------------------------------------
Author: ASF GitHub Bot
Created on: 24/Aug/21 15:43
Start Date: 24/Aug/21 15:43
Worklog Time Spent: 10m
Work Description: pzampino commented on a change in pull request #484:
URL: https://github.com/apache/knox/pull/484#discussion_r694971191
##########
File path:
gateway-service-knoxtoken/src/test/java/org/apache/knox/gateway/service/knoxtoken/TokenServiceResourceTest.java
##########
@@ -986,6 +986,30 @@ public void testUnlimitedTokensPerUser() throws Exception {
testLimitingTokensPerUser(String.valueOf("-1"), 100);
}
+ @Test
+ public void testTokenLimitChangeAfterAlreadyHavingTokens() throws Exception {
+ Map<String, String> contextExpectations = new HashMap<>();
+ contextExpectations.put(KNOX_TOKEN_USER_LIMIT, "-1");
+ configureCommonExpectations(contextExpectations, Boolean.TRUE);
+ TokenResource tr = new TokenResource();
+ tr.request = request;
+ tr.context = context;
+ tr.init();
+ // already have N tokens
+ int numberOfPreExistingTokens = 5;
+ for (int i = 0; i < numberOfPreExistingTokens; i++) {
+ tr.doGet();
+ }
+ Response getKnoxTokensResponse = tr.getUserTokens(USER_NAME);
+ Collection<String> tokens = ((Map<String, Collection<String>>)
JsonUtils.getObjectFromJsonString(getKnoxTokensResponse.getEntity().toString()))
+ .get("tokens");
+ assertEquals(tokens.size(), numberOfPreExistingTokens);
+ // change the limit and try generate one more
+ tr.setTokenLimitPerUser(numberOfPreExistingTokens -1);
+ Response response = tr.doGet();
+ assertTrue(response.getEntity().toString().contains("Unable to get token -
token limit exceeded."));
+ }
+
@Test
public void tesTokenLimitPerUserExceeded() throws Exception {
Review comment:
Could you also correct this test name to
tes**t**TokenLimitPerUserExceeded ?
##########
File path:
gateway-service-knoxtoken/src/main/java/org/apache/knox/gateway/service/knoxtoken/TokenResource.java
##########
@@ -741,4 +741,7 @@ private String safeGetMessage(Throwable t) {
return message != null ? message : "null";
}
+ void setTokenLimitPerUser(int tokenLimitPerUser) { // visible for testing
Review comment:
You could also use reflection in the test to set this, rather than
adding a method ONLY for testing.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 641152)
Time Spent: 0.5h (was: 20m)
> The tokenLimitPerUser check doesn't always work.
> ------------------------------------------------
>
> Key: KNOX-2646
> URL: https://issues.apache.org/jira/browse/KNOX-2646
> Project: Apache Knox
> Issue Type: Task
> Reporter: Attila Magyar
> Assignee: Attila Magyar
> Priority: Major
> Time Spent: 0.5h
> Remaining Estimate: 0h
>
> {code:java}
> if (tokenStateService.getTokens(p.getName()).size() == tokenLimitPerUser) {
> log.tokenLimitExceeded(p.getName());
> return Response.status(Response.Status.FORBIDDEN).entity("{ \"Unable to get
> token - token limit exceeded.\" }").build();
> }
> {code}
> We have an equality check when checking the max number of tokens per user.
> But if the user already have N number of tokens, and later the admin changes
> the gateway.knox.token.limit.per.user to a smaller number then this check
> will never trigger.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)