8000 [plugin-web-app] Move credentials from user info to http context in page steps by draker94 · Pull Request #4161 · vividus-framework/vividus · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[plugin-web-app] Move credentials from user info to http context in page steps #4161

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

Conversation

draker94
Copy link
Contributor
@draker94 draker94 commented Jul 21, 2023

Fixes #4134

@draker94 draker94 requested a review from a team as a code owner July 21, 2023 11:21
@codecov
Copy link
codecov bot commented Jul 21, 2023

Codecov Report

Merging #4161 (f07974b) into master (5bdd5a1) will increase coverage by 8.40%.
The diff coverage is 100.00%.

@@             Coverage Diff              @@
##             master    #4161      +/-   ##
============================================
+ Coverage     88.79%   97.19%   +8.40%     
+ Complexity     6672     6449     -223     
============================================
  Files           899      899              
  Lines         18555    18570      +15     
  Branches       1220     1223       +3     
============================================
+ Hits          16475    18050    +1575     
+ Misses         1951      411    -1540     
+ Partials        129      109      -20     
Impacted Files Coverage Δ
.../main/java/org/vividus/steps/ui/web/PageSteps.java 98.97% <100.00%> (+0.10%) ⬆️

... and 74 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Comment on lines 342 to 347
URI uriToRequest = pageUrl;
if (uriToRequest.getUserInfo() != null)
{
uriToRequest = moveUserInfoCredentialsToHttpContext(uriToRequest, context);
}
httpClient.doHttpHead(uriToRequest, context);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
URI uriToRequest = pageUrl;
if (uriToRequest.getUserInfo() != null)
{
uriToRequest = moveUserInfoCredentialsToHttpContext(uriToRequest, context);
}
httpClient.doHttpHead(uriToRequest, context);
URI pageUriToCheck = pageUrl;
UserInfo userInfo = UriUtils.getUserInfo(pageUriToCheck);
if (userInfo != null)
{
addBasicAuthToContext(userInfo, context);
pageUriToCheck = UriUtils.removeUserInfo(pageUriToCheck);
}
httpClient.doHttpHead(pageUriToCheck, context);

Comment on lines 369 to 381
private URI moveUserInfoCredentialsToHttpContext(URI pageUrl, HttpClientContext httpContext)
{
UserInfo userInfo = UriUtils.getUserInfo(pageUrl);
Credentials credentials = new UsernamePasswordCredentials(userInfo.getUser(),
userInfo.getPassword().toCharArray());
BasicScheme scheme = new BasicScheme();
scheme.initPreemptive(credentials);
AuthCache authCache = new BasicAuthCache();
HttpHost host = HttpHost.create(pageUrl);
authCache.put(host, scheme);
httpContext.setAuthCache(authCache);
return UriUtils.removeUserInfo(pageUrl);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private URI moveUserInfoCredentialsToHttpContext(URI pageUrl, HttpClientContext httpContext)
{
UserInfo userInfo = UriUtils.getUserInfo(pageUrl);
Credentials credentials = new UsernamePasswordCredentials(userInfo.getUser(),
userInfo.getPassword().toCharArray());
BasicScheme scheme = new BasicScheme();
scheme.initPreemptive(credentials);
AuthCache authCache = new BasicAuthCache();
HttpHost host = HttpHost.create(pageUrl);
authCache.put(host, scheme);
httpContext.setAuthCache(authCache);
return UriUtils.removeUserInfo(pageUrl);
}
private void addBasicAuthToContext(UserInfo userInfo, HttpClientContext httpContext)
{
Credentials credentials = new UsernamePasswordCredentials(userInfo.getUser(),
userInfo.getPassword().toCharArray());
BasicScheme scheme = new BasicScheme();
scheme.initPreemptive(credentials);
AuthCache authCache = new BasicAuthCache();
HttpHost host = HttpHost.create(pageUrl);
authCache.put(host, scheme);
httpContext.setAuthCache(authCache);
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also does it make sense to use org.apache.hc.client5.http.ContextBuilder#preemptiveBasicAuth?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also does it make sense to use org.apache.hc.client5.http.ContextBuilder#preemptiveBasicAuth?

Yep, this way looks pretty easier.

@valfirst valfirst modified the milestone: 0.5.12 Jul 21, 2023
@draker94 draker94 force-pushed the add_userinfo_handler_for_page_steps branch from 899ff3b to 169a5a8 Compare July 21, 2023 14:34
@draker94 draker94 force-pushed the add_userinfo_handler_for_page_steps branch from 169a5a8 to f07974b Compare July 21, 2023 14:37
@valfirst valfirst merged commit 3497225 into vividus-framework:master Jul 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error when trying to open the main page with userInfo
3 participants
0