Skip to content

Commit

Permalink
Adding additional properties for status messages (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
bhatti committed Nov 6, 2018
1 parent ccf6934 commit 16b6afe
Show file tree
Hide file tree
Showing 7 changed files with 307 additions and 37 deletions.
38 changes: 37 additions & 1 deletion .circleci/orb/orb-inline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@ orbs:
auto_score:
type: string
default: "50"
# Specify test username for automation testing
auto_username:
type: string
default: ""
# Specify test password for automation testing
auto_password:
type: string
default: ""
# Specify flag to show status messages from automation testing
auto_show_status_messages:
type: string
default: "false"
# Specify flag to show status messages from automation testing
auto_stop_tests_on_status:
type: string
default: ""
executor: inline_executor
steps:
- inline_command:
Expand All @@ -42,6 +58,10 @@ orbs:
auto_file: <<parameters.auto_file>>
auto_wait: <<parameters.auto_wait>>
auto_score: <<parameters.auto_score>>
auto_username: <<parameters.auto_username>>
auto_password: <<parameters.auto_password>>
auto_show_status_messages: <<parameters.auto_show_status_messages>>
auto_stop_tests_on_status: <<parameters.auto_stop_tests_on_status>>
commands:
inline_command:
parameters:
Expand Down Expand Up @@ -73,12 +93,28 @@ orbs:
auto_score:
type: string
default: "50"
# Specify test username for automation testing
auto_username:
type: string
default: ""
# Specify test password for automation testing
auto_password:
type: string
default: ""
# Specify flag to show status messages from automation testing
auto_show_status_messages:
type: string
default: "false"
# Specify flag to show status messages from automation testing
auto_stop_tests_on_status:
type: string
default: ""
steps:
- attach_workspace:
at: /tmp/workspace
- run: cp apkpure_app_887.apk /tmp/workspace/test.apk
- run: curl -Ls https://github.com/nowsecure/auto-circleci-plugin/archive/1.0.4.tar.gz | tar -xzf - -C .
- run: cd auto-circleci-plugin-1.0.4 && gradle run -Dauto.url=<< parameters.auto_url >> -Dauto.token=<< parameters.auto_token >> -Dauto.dir=<< parameters.auto_dir >> -Dauto.file=<< parameters.auto_file >> -Dauto.group=<< parameters.auto_group >> -Dauto.wait=<< parameters.auto_wait >> -Dauto.score=<< parameters.auto_score >>
- run: cd auto-circleci-plugin-1.0.4 && gradle run -Dauto.url=<< parameters.auto_url >> -Dauto.token=<< parameters.auto_token >> -Dauto.dir=<< parameters.auto_dir >> -Dauto.file=<< parameters.auto_file >> -Dauto.group=<< parameters.auto_group >> -Dauto.wait=<< parameters.auto_wait >> -Dauto.score=<< parameters.auto_score >> -Dauto.username=<<parameters.auto_username>> -Dauto.password=<<parameters.auto_password>> -Dauto.show.status.messages=<<parameters.auto_show_status_messages>> -Dauto.stop.tests.on.status=<<parameters.auto_stop_tests_on_status>>
- persist_to_workspace:
root: /tmp/workspace
paths:
Expand Down
18 changes: 17 additions & 1 deletion .circleci/orb/orb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,27 @@ commands:
auto_score:
type: string
default: "50"
# Specify test username for automation testing
auto_username:
type: string
default: ""
# Specify test password for automation testing
auto_password:
type: string
default: ""
# Specify flag to show status messages from automation testing
auto_show_status_messages:
type: string
default: "false"
# Specify flag to show status messages from automation testing
auto_stop_tests_on_status:
type: string
default: ""
steps:
- attach_workspace:
at: /tmp/workspace
- run: curl -Ls https://github.com/nowsecure/auto-circleci-plugin/archive/1.0.4.tar.gz | tar -xzf - -C .
- run: cd auto-circleci-plugin-1.0.4 && gradle run -Dauto.url=<< parameters.auto_url >> -Dauto.token=<< parameters.auto_token >> -Dauto.dir=<< parameters.auto_dir >> -Dauto.file=<< parameters.auto_file >> -Dauto.group=<< parameters.auto_group >> -Dauto.wait=<< parameters.auto_wait >> -Dauto.score=<< parameters.auto_score >>
- run: cd auto-circleci-plugin-1.0.4 && gradle run -Dauto.url=<< parameters.auto_url >> -Dauto.token=<< parameters.auto_token >> -Dauto.dir=<< parameters.auto_dir >> -Dauto.file=<< parameters.auto_file >> -Dauto.group=<< parameters.auto_group >> -Dauto.wait=<< parameters.auto_wait >> -Dauto.score=<< parameters.auto_score >> -Dauto.username=<<parameters.auto_username>> -Dauto.password=<<parameters.auto_password>> -Dauto.show.status.messages=<<parameters.auto_show_status_messages>> -Dauto.stop.tests.on.status=<<parameters.auto_stop_tests_on_status>>
- persist_to_workspace:
root: /tmp/workspace
paths:
Expand Down
91 changes: 79 additions & 12 deletions src/main/java/com/nowsecure/auto/circleci/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public class Main implements NSAutoParameters, NSAutoLogger {
private String apiKey;
private File artifactsDir;
private String description;
private String username;
private String password;
private boolean showStatusMessages;
private String stopTestsForStatusMessage;

private final IOHelperI helper = new IOHelper(PLUGIN_NAME, TIMEOUT);

Expand Down Expand Up @@ -137,15 +141,52 @@ public void setScoreThreshold(int scoreThreshold) {
this.scoreThreshold = scoreThreshold;
}

@Override
public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

@Override
public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

@Override
public boolean isShowStatusMessages() {
return showStatusMessages;
}

public void setShowStatusMessages(boolean showStatusMessages) {
this.showStatusMessages = showStatusMessages;
}

@Override
public String getStopTestsForStatusMessage() {
return stopTestsForStatusMessage;
}

public void setStopTestsForStatusMessage(String stopTestsForStatusMessage) {
this.stopTestsForStatusMessage = stopTestsForStatusMessage;
}

public void execute() throws IOException {
new NSAutoGateway(this, this, helper).execute();
}

@Override
public String toString() {
return "Main [artifactsDir=" + artifactsDir + ", apiUrl=" + apiUrl + ", group=" + group + ", file=" + file
+ ", waitMinutes=" + waitMinutes + ", breakBuildOnScore=" + breakBuildOnScore + ", scoreThreshold="
+ scoreThreshold + ", apiKey=" + apiKey + "]";
return "Main [apiUrl=" + apiUrl + ", group=" + group + ", file=" + file + ", waitMinutes=" + waitMinutes
+ ", breakBuildOnScore=" + breakBuildOnScore + ", scoreThreshold=" + scoreThreshold + ", artifactsDir="
+ artifactsDir + ", username=" + username + ", showStatusMessages=" + showStatusMessages
+ ", stopTestsForStatusMessage=" + stopTestsForStatusMessage + "]";
}

private static int parseInt(String name) {
Expand Down Expand Up @@ -198,12 +239,16 @@ private void usage(String msg) {

System.err.println(msg);
System.err.println("Usage:\n");
System.err.println(
"\tgradle run --args=\"-u auto-url -d artifacts-dir -t api-token -t mobile-binary-file -g user-group -f binary-file -w wait-for-completion-in-minutes -s min-score-to-pass\"");
System.err
.println(
"\tgradle run --args=\"--auto-url auto-url --auto-dir artifacts-dir --auto-token api-token --auto-group user-group"
+ " --auto-username test-username --auto-password test-password --auto-show-status-messages true|false to show status-messages --auto-stop-tests-on-status status-message to stop tests"
+ " --auto-file binary-file --auto-wait wait-for-completion-in-minutes --auto-score min-score-to-pass \"");
System.err.println("\tOR");
System.err
.println(
"Usage: gradle run -Dauto.dir=artifacts-dir -Dauto.url=auto-url -Dauto.token=api-token -Dauto.file=mobile-binary-file"
+ " -Dauto.username test-username -Dauto.password test-password -Dauto.show.status.messages true|false show status-messages -Dauto.stop.tests.on.status status-message to stop tests"
+ " -Dauto.group=user-group -Dauto.file=binary-file -Dauto.wait=wait-for-completion-in-minutes -Dauto.score=min-score-to-pass");
System.err.println("\tDefault url is " + DEFAULT_URL);
System.err.println("\tDefault auto-wait is 0, which means just upload without waiting for results");
Expand All @@ -216,22 +261,31 @@ private static boolean isEmpty(String m) {
return m == null || m.trim().length() == 0;
}

//
private void parseArgs(String[] args) {
for (int i = 0; i < args.length - 1; i++) {
if ("-u".equals(args[i])) {
if ("--auto-url".equals(args[i])) {
this.apiUrl = args[i + 1].trim();
} else if ("-g".equals(args[i])) {
} else if ("--auto-group".equals(args[i])) {
this.apiUrl = args[i + 1].trim();
} else if ("-d".equals(args[i])) {
} else if ("--auto-dir".equals(args[i])) {
this.artifactsDir = new File(args[i + 1].trim());
} else if ("-f".equals(args[i])) {
} else if ("--auto-file".equals(args[i])) {
this.file = new File(args[i + 1].trim());
} else if ("-t".equals(args[i])) {
} else if ("--auto-token".equals(args[i])) {
this.apiKey = args[i + 1].trim();
} else if ("-w".equals(args[i])) {
} else if ("--auto-wait".equals(args[i])) {
this.waitMinutes = Integer.parseInt(args[i + 1].trim());
} else if ("-s".equals(args[i])) {
} else if ("--auto-score".equals(args[i])) {
this.scoreThreshold = Integer.parseInt(args[i + 1].trim());
} else if ("--auto-username".equals(args[i])) {
this.username = args[i + 1].trim();
} else if ("--auto-password".equals(args[i])) {
this.password = args[i + 1].trim();
} else if ("--auto-show-status-messages".equals(args[i])) {
this.showStatusMessages = Boolean.valueOf(args[i + 1].trim());
} else if ("--auto-stop-tests-on-status".equals(args[i])) {
this.stopTestsForStatusMessage = args[i + 1].trim();
}
}
if (isEmpty(this.group)) {
Expand Down Expand Up @@ -273,6 +327,18 @@ private void parseArgs(String[] args) {
if (this.scoreThreshold == 0) {
this.scoreThreshold = parseInt("auto.score");
}
if (isEmpty(this.username)) {
this.username = getString("auto.username", "");
}
if (isEmpty(this.password)) {
this.password = getString("auto.password", "");
}
if (!this.showStatusMessages) {
this.showStatusMessages = getString("auto.show.status.messages", "").length() > 0;
}
if (isEmpty(this.stopTestsForStatusMessage)) {
this.stopTestsForStatusMessage = getString("auto.stop.tests.on.status", "");
}
}

@Override
Expand All @@ -286,4 +352,5 @@ public void error(String msg) {
System.err.println(new Date() + "@" + IOHelper.getLocalHost() + ":" + PLUGIN_NAME + " v" + IOHelper.getVersion()
+ " " + msg);
}

}
33 changes: 33 additions & 0 deletions src/main/java/com/nowsecure/auto/domain/Message.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.nowsecure.auto.domain;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;

public class Message {

public static List<String> fromJson(String json) throws ParseException, IOException {
if (json.startsWith("{")) {
throw new IOException("Failed to find message " + json);
}
JSONParser parser = new JSONParser();
JSONArray jsonArray = (JSONArray) parser.parse(json);
//
List<String> msgs = new ArrayList<String>();
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject jsonObject = (JSONObject) jsonArray.get(i);
String msg = (String) jsonObject.get("message");
if (msg != null) {
msgs.add(msg);
}
}

return msgs;
}

}
8 changes: 8 additions & 0 deletions src/main/java/com/nowsecure/auto/domain/NSAutoParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,12 @@ public interface NSAutoParameters {

int getScoreThreshold();

String getUsername();

String getPassword();

boolean isShowStatusMessages();

String getStopTestsForStatusMessage();

}
Loading

0 comments on commit 16b6afe

Please sign in to comment.