Skip to content
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

Fix for https://github.com/Cognifide/SecureCQ/issues/19 #20

Merged
merged 6 commits into from
Jul 25, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
IP2017-75 a few elements from DefaultPasswordsTest refactored
  • Loading branch information
Artur Mackowiak committed Jul 24, 2017
commit ff562094fb0f19ba7de47a13827415c944542a3a
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
*/
public class DefaultPasswordsTest extends AbstractTest implements AuthorTest, PublishTest {

private static final String LOGIN_PATH = "/libs/granite/core/content/login.html/j_security_check";
private static final String USERNAME_FORM_PARAM_NAME = "j_username";
private static final String ALTERNATIVE_LOGIN_PATH = "/libs/granite/core/content/login.html/j_security_check";
private static final String PASSWORD_FORM_PARAM_NAME = "j_password";
private static final String IS_VALIDATE_FORM_PARAM_NAME = "j_validate";

Expand All @@ -39,12 +39,12 @@ public DefaultPasswordsTest(Configuration config) {

@Override
public boolean doTest(String url, String instanceName) throws Exception {
String alternativeUrl = url + ALTERNATIVE_LOGIN_PATH;
String loginUrl = url + LOGIN_PATH;
boolean ok = true;
String[] users = config.getStringList("users");
for (String user : users) {
String[] split = UserHelper.splitUser(user);
if (split[1] != null && remoteUserExists(split, alternativeUrl)) {
if (split[1] != null && remoteUserExists(split, loginUrl)) {
addErrorMessage("User %s exists on %s", user, instanceName);
ok = false;
} else {
Expand All @@ -59,7 +59,7 @@ private boolean remoteUserExists(String[] user, String url) throws URISyntaxExce
DefaultHttpClient authorizedClient = new DefaultHttpClient();

HttpPost httpPost = new HttpPost(url);
List<NameValuePair> params = getRequestParamsList(user);
List<NameValuePair> params = getPostParamsList(user);
httpPost.setEntity(new UrlEncodedFormEntity(params));

HttpResponse response = authorizedClient.execute(httpPost);
Expand All @@ -68,7 +68,7 @@ private boolean remoteUserExists(String[] user, String url) throws URISyntaxExce
return code != HttpURLConnection.HTTP_FORBIDDEN;
}

private List<NameValuePair> getRequestParamsList(String[] user) {
private List<NameValuePair> getPostParamsList(String[] user) {
List<NameValuePair> params = new ArrayList<>();

params.add(new BasicNameValuePair(USERNAME_FORM_PARAM_NAME, user[0]));
Expand Down