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

DEF-1079012 [Bamboo]Always failed to execute the task of ALM Lab Management in ALM SSO server #96

Merged
merged 4 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 5 additions & 8 deletions HpToolsLauncher/Common/McConnectionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,12 @@ public McConnectionInfo()
}

// if token auth was specified this is populated
private AuthTokenInfo _tokens;
private AuthTokenInfo _token;
private string _execToken;
private AuthType _authType = AuthType.UsernamePassword;

public string UserName { get; set; }
public string Password { get; set; }
public string ClientId { get; set; }
public string SecretKey { get; set; }

public string ExecToken
{
Expand All @@ -108,7 +106,7 @@ public string ExecToken
set
{
_execToken = value;
_tokens = ParseExecToken();
_token = ParseExecToken();
}
}

Expand Down Expand Up @@ -311,8 +309,7 @@ private AuthTokenInfo ParseExecToken()
var execToken = ExecToken.Trim().Trim(DBL_QUOTE);

var ret = new AuthTokenInfo();

if (execToken.Length == 0) return ret; // empty string was given as token, may semnalize that it wasn't specified
if (execToken.Length == 0) return ret; // empty string was given as token, may semnalize that it wasn't specified

var tokens = execToken.Split(TOKEN_SEPARATOR.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

Expand Down Expand Up @@ -359,7 +356,7 @@ private AuthTokenInfo ParseExecToken()
/// <returns></returns>
public AuthTokenInfo GetAuthToken()
{
return _tokens;
return _token;
}

private string UseSslAsStr => UseSslAsInt == ONE ? YES : NO;
Expand All @@ -375,7 +372,7 @@ public override string ToString()
string usernameOrClientId = string.Empty;
if (MobileAuthType == AuthType.AuthToken)
{
usernameOrClientId = $"ClientId: {ClientId}";
usernameOrClientId = $"ClientId: {_token.ClientId}";
}
else if (MobileAuthType == AuthType.UsernamePassword)
{
Expand Down
11 changes: 10 additions & 1 deletion HpToolsLauncher/Launcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ public Launcher(string failOnTestFailed, string paramFileName, TestStorageType r
/// <returns></returns>
private string Decrypt(string textToDecrypt)
{
if (textToDecrypt.IsNullOrWhiteSpace())
return string.Empty;

RijndaelManaged rijndaelCipher = new()
{
Mode = CipherMode.CBC,
Expand Down Expand Up @@ -293,6 +296,10 @@ IAssetRunner CreateRunner(TestStorageType runType)
{
mcConnectionInfo = new McConnectionInfo(_ciParams);
}
catch (NoMcConnectionException)
{
// no action, the Test will use the default UFT One settings
}
catch (Exception ex)
{
ConsoleWriter.WriteErrLine(ex.Message);
Expand Down Expand Up @@ -427,7 +434,9 @@ private void RunTests(IAssetRunner runner, string resultsFile)
ConsoleWriter.WriteLine(string.Format(Resources.LauncherRunnerDisposeError, ex.Message));
};
}

}
public class NoMcConnectionException : Exception
{
}

}
Expand Down
3 changes: 2 additions & 1 deletion HpToolsLauncher/Runners/FileSystemTestsRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ public FileSystemTestsRunner(List<string> sources,
Environment.Exit((int)Launcher.ExitCodeEnum.Failed);
}

ConsoleWriter.WriteLine("Digital Lab connection info is - " + _mcConnection.ToString());
if (_mcConnection != null)
ConsoleWriter.WriteLine("Digital Lab connection info is - " + _mcConnection.ToString());

ConsoleWriter.WriteLine(string.Format(Resources.FsRunnerTestsFound, _tests.Count));
_tests.ForEach(t => ConsoleWriter.WriteLine(t.TestName));
Expand Down
1 change: 1 addition & 0 deletions HpToolsLauncher/TestRunners/GuiTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public GuiTestRunner(IAssetRunner runNotifier, bool useUftLicense, TimeSpan time

private void SetMobileInfo()
{
if (_mcConnection == null) return;
#region Mc connection and other mobile info

// Mc Address, username and password
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws S
JobOperation operation = null;

if (CommonUtils.doCheck(serverUrl, userName, password)) {

try {
//1:no proxy 2:config proxy, but proxy info is null 3:config proxy, no auth 4: config proxy config auth, but auth null 5:cinfig proxy,auth
if (isProxy) {
Expand Down Expand Up @@ -97,19 +96,12 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws S
operation = new JobOperation(serverUrl, userName, password, null, null, null);//1
msg = send(operation,req);
}


} catch (Exception e) {

}

} catch (Exception e) { }
} else {
msg = "{\"myErrorCode\":\"0\"}";//0 userName password or url null
}


writeJSON(resp, msg);

}

private String send(JobOperation operation,HttpServletRequest req) throws Exception{
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/com/adm/utils/uft/integration/HttpResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@

import net.minidev.json.JSONObject;

import java.net.HttpURLConnection;
import java.util.List;
import java.util.Map;

public class HttpResponse {

private Map<String, List<String>> headers;
private JSONObject jsonObject;
private String responseCode;
private int responseCode;
private String responseMessage;

public HttpResponse() {

Expand All @@ -40,13 +42,19 @@ public HttpResponse(Map<String, List<String>> headers, JSONObject jsonObject) {
this.jsonObject = jsonObject;
}

public String getResponseCode() {
public int getResponseCode() {
return responseCode;
}
public String getResponseMessage() {
return responseMessage;
}

public void setResponseCode(String responseCode) {
public void setResponseCode(int responseCode) {
this.responseCode = responseCode;
}
public void setResponseMessage(String message) {
this.responseMessage = message;
}

public void setHeaders(Map<String, List<String>> headers) {
this.headers = headers;
Expand Down
18 changes: 4 additions & 14 deletions src/main/java/com/adm/utils/uft/integration/HttpUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public class HttpUtils {
public static final String POST = "POST";
public static final String GET = "GET";


private HttpUtils() {

}
Expand All @@ -60,15 +59,13 @@ public static HttpResponse get(ProxyInfo proxyInfo, String url, Map<String, Stri
return response;
}


private static HttpResponse doHttp(ProxyInfo proxyInfo, String requestMethod, String connectionUrl, String queryString, Map<String, String> headers, byte[] data) throws IOException {
HttpResponse response = new HttpResponse();

if ((queryString != null) && !queryString.isEmpty()) {
connectionUrl += "?" + queryString;
}


URL url = new URL(connectionUrl);

HttpURLConnection connection = (HttpURLConnection) openConnection(proxyInfo, url);
Expand All @@ -91,11 +88,11 @@ private static HttpResponse doHttp(ProxyInfo proxyInfo, String requestMethod, St

connection.connect();

int resCode = connection.getResponseCode();
response.setResponseCode(resCode);
response.setResponseMessage(connection.getResponseMessage());

int responseCode = connection.getResponseCode();
response.setResponseCode(String.valueOf(responseCode));

if (responseCode == HttpURLConnection.HTTP_OK) {
if (resCode == HttpURLConnection.HTTP_OK || resCode == HttpURLConnection.HTTP_CREATED || resCode == HttpURLConnection.HTTP_ACCEPTED) {
InputStream inputStream = connection.getInputStream();
JSONObject jsonObject = convertStreamToJSONObject(inputStream);
Map<String, List<String>> headerFields = connection.getHeaderFields();
Expand All @@ -121,7 +118,6 @@ private static URLConnection openConnection(final ProxyInfo proxyInfo, URL _url)
} catch (Exception e) {
e.printStackTrace();
}

}

if (proxy != null && proxyInfo._userName != null && proxyInfo._password != null && !proxyInfo._password.isEmpty() && !proxyInfo._password.isEmpty()) {
Expand All @@ -132,19 +128,16 @@ protected PasswordAuthentication getPasswordAuthentication() {
}
};


Authenticator.setDefault(authenticator);
}

if (proxy == null) {
return _url.openConnection();
}


return _url.openConnection(proxy);
}


private static void setConnectionHeaders(HttpURLConnection connection, Map<String, String> headers) {

if (connection != null && headers != null && headers.size() != 0) {
Expand All @@ -154,7 +147,6 @@ private static void setConnectionHeaders(HttpURLConnection connection, Map<Strin
connection.setRequestProperty(header.getKey(), header.getValue());
}
}

}

private static JSONObject convertStreamToJSONObject(InputStream inputStream) {
Expand Down Expand Up @@ -237,8 +229,6 @@ public ProxyInfo(String host, String port, String userName, String password) {
_userName = userName;
_password = password;
}

}


}
Loading