Skip to content

Commit

Permalink
IP2017-75 code reformatted again
Browse files Browse the repository at this point in the history
  • Loading branch information
Artur Mackowiak committed Jul 24, 2017
1 parent 9126bcf commit 59eef29
Showing 1 changed file with 40 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,54 +29,54 @@
*/
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 PASSWORD_FORM_PARAM_NAME = "j_password";
private static final String IS_VALIDATE_FORM_PARAM_NAME = "j_validate";
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 PASSWORD_FORM_PARAM_NAME = "j_password";
private static final String IS_VALIDATE_FORM_PARAM_NAME = "j_validate";

public DefaultPasswordsTest(Configuration config) {
super(config);
}
public DefaultPasswordsTest(Configuration config) {
super(config);
}

@Override
public boolean doTest(String url, String instanceName) throws Exception {
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, loginUrl)) {
addErrorMessage("User %s exists on %s", user, instanceName);
ok = false;
} else {
addInfoMessage("User %s doesn't exists on %s", user, instanceName);
}
}
return ok;
@Override
public boolean doTest(String url, String instanceName) throws Exception {
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, loginUrl)) {
addErrorMessage("User %s exists on %s", user, instanceName);
ok = false;
} else {
addInfoMessage("User %s doesn't exists on %s", user, instanceName);
}
}
return ok;
}

private boolean remoteUserExists(String[] user, String url) throws URISyntaxException,
IOException, AuthenticationException {
DefaultHttpClient authorizedClient = new DefaultHttpClient();
private boolean remoteUserExists(String[] user, String url) throws URISyntaxException,
IOException, AuthenticationException {
DefaultHttpClient authorizedClient = new DefaultHttpClient();

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

HttpResponse response = authorizedClient.execute(httpPost);
EntityUtils.consume(response.getEntity());
int code = response.getStatusLine().getStatusCode();
return code != HttpURLConnection.HTTP_FORBIDDEN;
}
HttpResponse response = authorizedClient.execute(httpPost);
EntityUtils.consume(response.getEntity());
int code = response.getStatusLine().getStatusCode();
return code != HttpURLConnection.HTTP_FORBIDDEN;
}

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

params.add(new BasicNameValuePair(USERNAME_FORM_PARAM_NAME, user[0]));
params.add(new BasicNameValuePair(PASSWORD_FORM_PARAM_NAME, user[1]));
params.add(new BasicNameValuePair(IS_VALIDATE_FORM_PARAM_NAME, "true"));
params.add(new BasicNameValuePair(USERNAME_FORM_PARAM_NAME, user[0]));
params.add(new BasicNameValuePair(PASSWORD_FORM_PARAM_NAME, user[1]));
params.add(new BasicNameValuePair(IS_VALIDATE_FORM_PARAM_NAME, "true"));

return params;
}
return params;
}

}

0 comments on commit 59eef29

Please sign in to comment.