Removing tests for the old platform requirements

This commit is contained in:
Eduardo Vozniak 2023-10-02 10:56:52 -03:00
parent aaf290193e
commit 9546f84203
No known key found for this signature in database
GPG Key ID: ACB52F85E23B1C50
49 changed files with 0 additions and 3891 deletions

View File

@ -1,22 +0,0 @@
[*.cs]
# PH2028: Copyright Present
dotnet_diagnostic.PH2028.severity = none
# PH2006: Namespace matches File Path
dotnet_diagnostic.PH2006.severity = none
# PH 2071: change default token count for code duplication detection
dotnet_code_quality.PH2071.token_count = 100
# PH2079: Specify the namespace prefix in the .editorconfig file
dotnet_code_quality.PH2079.namespace_prefix = Philips.EDI.Foundation
# PH2019: TestCleanup methods not allowed
dotnet_diagnostic.PH2019.severity = none
# PH2016: TestInitialize methods not allowed
dotnet_diagnostic.PH2016.severity = none
dotnet_code_quality.PH2015.allowed_test_categories = TestCategory.GatedSanity,TestCategory.Nightly,TestCategory.PostDeployment,TestCategory.WithoutMultitenancy,TestCategory.MultitenancyWithOrgNameAsSubdomain,TestCategory.MultitenancyWithOrgIdInHeader

View File

@ -1,51 +0,0 @@
using System;
using Utilities;
using Driver.UI.Common;
using Driver.UI.Interfaces;
using Philips.EDI.Foundation.APIGateway.AutomationTest.Utilities;
namespace Philips.EDI.Foundation.APIGateway.AutomationTest.BusinessLayer
{
public class AuthenticationBL
{
private readonly IWebDriverUi _webDriver;
public AuthenticationBL(IWebDriverUi webDriver)
{
_webDriver = webDriver;
}
public Cookies GetCookie(string cookieName)
{
Logger.InfoStartMethod();
try
{
Logger.Info($"Get the cookie Named: {cookieName}");
var cookies = _webDriver.GetAllCookies();
return cookies.Find(x => x.CookieName.EqualsWithIgnoreCase(cookieName));
}
catch (Exception ex)
{
Logger.InfoFailedWithException(ex);
throw;
}
}
public void SetCookie(Cookies cookie)
{
Logger.InfoStartMethod();
try
{
Logger.Info($"Cookie Name: {cookie.CookieName}");
Logger.Info($"Cookie Value: {cookie.CookieValue}");
_webDriver.DeleteCookieNamed(cookie.CookieName);
_webDriver.AddNewCookie(cookie);
}
catch (Exception ex)
{
Logger.InfoFailedWithException(ex);
throw;
}
}
}
}

View File

@ -1,50 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Reflection;
using Newtonsoft.Json.Linq;
using Philips.EDI.Foundation.APIGateway.AutomationTest.Utilities;
using Utilities;
namespace Philips.EDI.Foundation.APIGateway.AutomationTest.BusinessLayer
{
public class CommonBL
{
public JObject GetImposterRecordedRequests(string apiGatewayBaseUrl, Dictionary<string, string> headers, string mockserviceJsonConfigFile)
{
try
{
string mockserviceJsonConfigFilePath = Path.Join(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Tests", "Data", "MockServiceConfigs", mockserviceJsonConfigFile);
Logger.Info($"Mockservice json config file path: {mockserviceJsonConfigFilePath}");
string port = JObject.Parse(File.ReadAllText(mockserviceJsonConfigFilePath))["port"].ToString();
string imposterGetUrl = $"{apiGatewayBaseUrl}/imposters/{port}";
Logger.Info($"Imposter Get Url: { imposterGetUrl}");
return HttpClientUtility.ExecuteAndGetResponse(HttpMethod.Get, imposterGetUrl, headers, null);
}
catch (Exception ex)
{
Logger.InfoFailedWithException(ex);
throw;
}
}
public JToken GetUpstreamRecordedRequest(string apiGatewayBaseUrl, Dictionary<string, string> headers, string customUniqueRequestIdHeaderName, string customUniqueRequestIdHeaderValue, string mockserviceJsonConfigFile)
{
try
{
var getResponseBody = GetImposterRecordedRequests(apiGatewayBaseUrl, headers, mockserviceJsonConfigFile);
Logger.Info($"Response body: {getResponseBody}");
JToken testRecordedRequest = getResponseBody["requests"].Where(x => x["headers"][customUniqueRequestIdHeaderName] != null && x["headers"][customUniqueRequestIdHeaderName].ToString() == customUniqueRequestIdHeaderValue).FirstOrDefault();
return testRecordedRequest;
}
catch (Exception ex)
{
Logger.InfoFailedWithException(ex);
throw;
}
}
}
}

View File

@ -1,128 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using Utilities;
using Philips.EDI.Foundation.APIGateway.AutomationTest.Utilities;
using Utilities.Wait;
namespace Philips.EDI.Foundation.APIGateway.AutomationTest.BusinessLayer
{
public class HSPIAMBusinessLayer
{
public string GetRoleId(string idmClientBaseUrl, Dictionary<string, string> headers, string OrgId, string roleName)
{
try
{
string idmClientRoleUrl = $"{idmClientBaseUrl}/Role?organizationId={OrgId}&name={roleName}";
Logger.Info($"Get Role url: {idmClientRoleUrl}");
headers.TryAdd("api-version", "1");
var responseBody = HttpClientUtility.ExecuteAndGetResponse(HttpMethod.Get, idmClientRoleUrl, headers, null);
var entry = responseBody["entry"]?.FirstOrDefault();
var roleId = entry?["id"]?.ToString();
Logger.Info($"Role Id: {roleId}");
return roleId;
}
catch (Exception ex)
{
Logger.InfoFailedWithException(ex);
throw;
}
}
public List<string> GetAllPersmissionsFromRole(string idmClientBaseUrl, Dictionary<string, string> headers, string roleID)
{
try
{
string idmClientPermissionsUrl = $"{idmClientBaseUrl}/Permission?roleId={roleID}";
Logger.Info($"Get Permission url: {idmClientPermissionsUrl}");
var responseBody = HttpClientUtility.ExecuteAndGetResponse(HttpMethod.Get, idmClientPermissionsUrl, headers, null);
return responseBody["entry"]?.Select(x => x["name"].ToString()).ToList();
}
catch (Exception ex)
{
Logger.InfoFailedWithException(ex);
throw;
}
}
public bool AssignPermissionToRole(string idmClientBaseUrl, Dictionary<string, string> headers, string roleID, string permissionsJson)
{
try
{
return ManipulatePersmissionsInRole(idmClientBaseUrl, "assign-permission", headers, roleID, permissionsJson);
}
catch (Exception ex)
{
Logger.InfoFailedWithException(ex);
throw;
}
}
public bool RemovePermissionFromRole(string idmClientBaseUrl, Dictionary<string, string> headers, string roleID, string permissionsJson)
{
try
{
return ManipulatePersmissionsInRole(idmClientBaseUrl, "remove-permission", headers, roleID, permissionsJson);
}
catch (Exception ex)
{
Logger.InfoFailedWithException(ex);
throw;
}
}
private bool ManipulatePersmissionsInRole(string idmClientBaseUrl, string permissionType, Dictionary<string, string> headers, string roleID, string permissionsJson)
{
string iamClientRoleUrl = $"{idmClientBaseUrl}/Role/{roleID}/${permissionType}";
Logger.Info($"Role manipulation url: {iamClientRoleUrl}");
var httpContent = HttpClientUtility.CreateHttpContent(permissionsJson);
var response = HttpClientUtility.ExecuteAsync(HttpMethod.Post, iamClientRoleUrl, headers, httpContent).Result;
Sleep.Seconds(5);
return response.StatusCode == HttpStatusCode.OK;
}
/// <summary>
/// Getting the user details from IAM
/// </summary>
/// <param name="iamGetUserUrl">URL to get the user details form IAM</param>
/// <param name="userMailId">user mail id to get details</param>
/// <param name="headers">headers</param>
/// <returns>List of usersUUID based on mail id</returns>
public List<string> GetUserDetails(string iamGetUserUrl, string userMailId, Dictionary<string, string> headers)
{
string finalUrl = $"{iamGetUserUrl}{userMailId}";
Logger.Info($"Get Users url: {finalUrl}");
headers.TryAdd("api-version","2");
var responseBody = HttpClientUtility.ExecuteAndGetResponse(HttpMethod.Get, finalUrl, headers, null);
if (responseBody != null)
{
List <string> userLoginId = responseBody["entry"]?.Where(x => x["id"] != null).Select(x => x["id"].ToString()).ToList();
return userLoginId;
}
return null;
}
/// <summary>
/// Deleting the user based on userName and respective Organization ID
/// </summary>
/// <param name="iamGetUserUrl">URL to get the user details form IAM</param>
/// <param name="idmClientBaseUrl">IDM client Base URL</param>
/// <param name="userMailId">user mail id to be deleted</param>
/// <param name="headers">headers</param>
/// <returns>HttpMessage</returns>
public HttpResponseMessage DeleteUser(string iamGetUserUrl, string idmClientBaseUrl, string userMailId, Dictionary<string, string> headers)
{
List<string> userIdtoDelete = GetUserDetails(iamGetUserUrl, userMailId.ToLower(), headers);
headers.TryAdd("api-version", "2");
headers.TryAdd("Accept", "application/json");
if (userIdtoDelete.Count >= 1)
{
string deleteUrl = $"{idmClientBaseUrl}/User/{userIdtoDelete[0]}";
return HttpClientUtility.ExecuteAsync(HttpMethod.Delete, deleteUrl, headers, null).Result;
}
return null;
}
}
}

View File

@ -1,29 +0,0 @@
using Driver.UI.Interfaces;
using Philips.EDI.Foundation.APIGateway.AutomationTest.Utilities;
namespace Philips.EDI.Foundation.APIGateway.AutomationTest.BusinessLayer
{
public class ReverseProxyBL
{
private readonly IWebDriverUi _webDriver;
public ReverseProxyBL(IWebDriverUi webDriver)
{
_webDriver = webDriver;
}
public bool NavigateToImpostersPageAndGetIsMockServiceLinksDisplayed(string impostersUrl)
{
_webDriver.Goto(impostersUrl);
_webDriver.TakeScreenshot();
return _webDriver.IsDisplayed(_webDriver.FindElementByXPath("//table[@id='imposters']"));
}
public bool ClickOnImposterAndGetMockServiceContentIsDisplayed(string mockserviceName)
{
_webDriver.Click(_webDriver.FindElementByXPath($"//a[normalize-space(.)='{mockserviceName}']"));
_webDriver.TakeScreenshot();
return _webDriver.IsDisplayed(_webDriver.FindElementByXPath("//code[contains(.,'predicates')]"));
}
}
}

View File

@ -1,38 +0,0 @@
using System;
using System.IO;
using System.Security.Cryptography;
using System.Web;
namespace Philips.EDI.Foundation.APIGateway.AutomationTest.BusinessLayer
{
public class VueSSOTokenBL
{
public string GenerateSsoToken(string username, string sessionTime, string symmetricKey)
{
var ssoToken = $"user_name={username}&session_time={sessionTime}";
return EncryptSsoToken(ssoToken, symmetricKey);
}
private static string EncryptSsoToken(string toBeEncryptedUrl, string symmetricKey)
{
byte[] encrypted;
var Key = Convert.FromBase64String(symmetricKey);
byte[] IV = new byte[16];
using (AesManaged aes = new AesManaged())
{
ICryptoTransform encryptor = aes.CreateEncryptor(Key, IV);
using (MemoryStream ms = new MemoryStream())
{
using (CryptoStream cs = new CryptoStream(ms, encryptor, CryptoStreamMode.Write))
{
// Create StreamWriter and write data to a stream
using (StreamWriter sw = new StreamWriter(cs))
sw.Write(toBeEncryptedUrl);
encrypted = ms.ToArray();
return HttpUtility.UrlEncode(Convert.ToBase64String(encrypted));
}
}
}
}
}
}

View File

@ -1,51 +0,0 @@
{
"AppConfiguration": {
"RootFolder": "C:\\AutomationOutput",
"ReporterList": "html;word",
"RootEvidencePath": "C:\\AutomationOutput\\Evidences",
"DifidoFolderLocation": "difido-reports-common.jar",
"ProductName": "API Gateway",
"LessPayloadMockservice": "/mockserviceA/test",
"HeavyPayloadMockservice": "/mockserviceB/test",
"ServiceUnavailableMockservice": "/mockserviceX",
"MultitenancyMockservice": "/mockserviceA/multitenancy",
"LogoutPath": "/logout",
"CDRSubscriptionUrlPath": "/store/fhir/OrgId/Subscription",
"CDRImagingStudyUrlPath": "/store/fhir/OrgId/ImagingStudy",
"QidoStudyLevelUrlPathWithoutOrgId": "/dicom/qido/studies",
"IamBrokerConfigAPIRelativePath": "/IamTokenExchangeBroker/OrgId/config/",
"OpenIdConfigurationUrlPath": "/tokenvalidator/OrgId/openid-configuration",
"MountibankTimeoutinSeconds": "15"
},
"PipelineConfiguration": {
"SSOTokenUserName": "",
"OrgSymmetricKey": "",
"AuthUserName": "",
"AuthPassword": "",
"ServiceID": "",
"ServiceIDPrivateKey": "",
"IAMAuthorizationUrl": "",
"IAMAccessTokenUrl": "",
"IDMClientBaseUrl": "",
"IAMGetUserUrl": "",
"CDRBaseUrl": "",
"OauthClientID": "",
"OauthClientSecret": "",
"CFOrgName": "",
"CFSpaceName": "",
"CFUserName": "",
"CFPassword": "",
"CookieName": "",
"CFOauthTokenUrl": "",
"CFBaseUrl": "",
"CFAuthenticatorAppName": "",
"APIGatewayBaseUrl": "",
"OauthProxyCookieTimeoutInSeconds": "",
"AuthenticatorSessionExpireOffsetInPercent": "",
"AccessTokenTestRoleName": "",
"OpenIdConfigurationBaseUrl": "",
"OpenIdConfigOrganizationCertificateMapping": "",
"TenantDetails": ""
},
"ExecutionEnvironment": "Local"
}

View File

@ -1,23 +0,0 @@
namespace Philips.EDI.Foundation.APIGateway.AutomationTest.Models
{
public class AppConfiguration
{
public string RootFolder { get; set; }
public string ReporterList { get; set; }
public string RootEvidencePath { get; set; }
public string DifidoFolderLocation { get; set; }
public string ProductName { get; set; }
public string ProductVersion { get; set; }
public string LessPayloadMockservice { get; set; }
public string HeavyPayloadMockservice { get; set; }
public string ServiceUnavailableMockservice { get; set; }
public string MultitenancyMockservice { get; set; }
public string LogoutPath { get; set; }
public string CDRSubscriptionUrlPath { get; set; }
public string QidoStudyLevelUrlPathWithoutOrgId { get; set; }
public string CDRImagingStudyUrlPath { get; set; }
public string IamBrokerConfigAPIRelativePath { get; set; }
public string OpenIdConfigurationUrlPath { get; set; }
public int MountibankTimeoutinSeconds { get; set; }
}
}

View File

@ -1,17 +0,0 @@
namespace Philips.EDI.Foundation.APIGateway.AutomationTest.Models
{
public class Constants
{
public const string CustomUniqueRequestHeaderName = "customuniquerequestheader";
public const string AuthenticatorSessionExpireOffsetInPercent = "Authenticator_session__SessionExpireOffsetInPercent";
public const string ValidTenantKey = "ValidTenant";
public const string InvalidTenantKey = "InvalidTenant";
public const string AccessTokenTenantKey = "AccessTokenTenant";
public const string TimeStampFormat = "yyyy-MM-ddTHH:mm:ss";
public const int RetryTimeOutInSeconds = 30;
public const string SymmetricKeyName = "VUESSOSYMMETRICKEY";
public const string TimeZoneKeyName = "VUESSOTIMEZONE";
public const string TokyoTimeZone = "Tokyo Standard Time";
public const string UTCTimeZone = "UTC";
}
}

View File

@ -1,29 +0,0 @@
namespace Philips.EDI.Foundation.APIGateway.AutomationTest.Models
{
public enum TestCategory
{
GatedSanity,
Nightly,
PostDeployment,
WithoutMultitenancy,
OrgNameInUrl,
OrgIdInHeader,
UserAccessToken,
ServiceIDAccessToken,
BrowserLogout,
SSOToken,
IAMTokenExchangeBroker,
IAMTokenExchangeBrokerPreCondition,
IDTokenValidator,
OnPrem,
UpgradeSanity,
IntegratedSanity
}
public enum ExecutionEnvironment
{
Local,
Production
}
}

View File

@ -1,13 +0,0 @@
using Newtonsoft.Json;
namespace Philips.EDI.Foundation.APIGateway.AutomationTest.Models
{
public class OpenIdConfigOrganizationCertificateMapping
{
[JsonProperty("organizationId")]
public string OrganizationId { get; set; }
[JsonProperty("certificate")]
public string Certificate { get; set; }
}
}

View File

@ -1,36 +0,0 @@
using System.Collections.Generic;
namespace Philips.EDI.Foundation.APIGateway.AutomationTest.Models
{
public class PipelineConfiguration
{
public string AuthUserName { get; set; }
public string AuthPassword { get; set; }
public string APIGatewayBaseUrl { get; set; }
public string OauthClientID { get; set; }
public string OauthClientSecret { get; set; }
public string CFOrgName { get; set; }
public string CFSpaceName { get; set; }
public string CFUserName { get; set; }
public string CFPassword { get; set; }
public string CookieName { get; set; }
public string CFOauthTokenUrl { get; set; }
public string CFBaseUrl { get; set; }
public string CFAuthenticatorAppName { get; set; }
public int OauthProxyCookieTimeoutInSeconds { get; set; }
public string AuthenticatorSessionExpireOffsetInPercent { get; set; }
public string AccessTokenTestRoleName { get; set; }
public string IAMAuthorizationUrl { get; set; }
public string IAMAccessTokenUrl { get; set; }
public string ServiceID { get; set; }
public string ServiceIDPrivateKey { get; set; }
public string IDMClientBaseUrl { get; set; }
public string OrgSymmetricKey { get; set; }
public string CDRBaseUrl { get; set; }
public string IAMGetUserUrl { get; set; }
public string OpenIdConfigurationBaseUrl { get; set; }
public string SSOTokenUserName { get; set; }
public string OpenIdConfigOrganizationCertificateMapping { get; set; }
public string TenantDetails { get; set; }
}
}

View File

@ -1,12 +0,0 @@
using Newtonsoft.Json;
namespace Philips.EDI.Foundation.APIGateway.AutomationTest.Models
{
public class TenantMapping
{
[JsonProperty("tenantName")]
public string TenantName { get; set; }
[JsonProperty("iamOrganizationId")]
public string IamOrganizationId { get; set; }
}
}

View File

@ -1,70 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<NuspecFile>.\Philips.EDI.Foundation.APIGateway.AutomationTest.nuspec</NuspecFile>
<NuspecProperties>version=$(version);id=$(MSBuildProjectName)</NuspecProperties>
<NuspecBasePath>.\Bin\$(configuration)\$(TargetFramework)</NuspecBasePath>
<IsPackable>true</IsPackable>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<RunPostBuildEvent>OnOutputUpdated</RunPostBuildEvent>
<NoWarn>PH2075</NoWarn>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Compile Remove="Tests\Data\EnvoyConfigs\**" />
<EmbeddedResource Remove="Tests\Data\EnvoyConfigs\**" />
<None Remove="Tests\Data\EnvoyConfigs\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="AutomationFramework.Driver" Version="1.3.5" />
<PackageReference Include="AutomationFramework.Reporters" Version="1.2.0" />
<PackageReference Include="AutomationFramework.Utilities" Version="1.2.4" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.3" />
<PackageReference Include="coverlet.collector" Version="3.0.2" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.3" />
<PackageReference Include="Philips.CodeAnalysis.DuplicateCodeAnalyzer" Version="1.1.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Philips.CodeAnalysis.MaintainabilityAnalyzers" Version="1.2.6.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Philips.CodeAnalysis.MoqAnalyzers" Version="1.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Philips.CodeAnalysis.MsTestAnalyzers" Version="1.1.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="90.0.4430.2400" />
<PackageReference Include="TimeZoneConverter" Version="3.5.0" />
</ItemGroup>
<ItemGroup>
<None Update="Env.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="log4net.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Tests\Data\MockServiceConfigs\LessPayloadMockservice.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Tests\Data\MockServiceConfigs\HeavyPayloadMockservice.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Resource Include="Tests\Data\MockserviceA.json" />
<Resource Include="Tests\Data\MockserviceB.json" />
</ItemGroup>
</Project>

View File

@ -1,36 +0,0 @@
{
"PipelineConfiguration": {
"SSOTokenUserName": "",
"OrgSymmetricKey": "",
"AuthUserName": "sai.chand@philips.com",
"AuthPassword": "",
"ServiceID": "apigateway-nightly.apigateway-nightly.pf-nightly-tf@pf-nightly-tf.edi-platform-service.ediplatform.philips-healthsuite.com",
"ServiceIDPrivateKey": "",
"IAMAuthorizationUrl": "https://iam-client-test.us-east.philips-healthsuite.com/authorize/oauth2/token",
"IAMAccessTokenUrl": "https://iam-client-test.us-east.philips-healthsuite.com/oauth2/access_token",
"IDMClientBaseUrl": "https://idm-client-test.us-east.philips-healthsuite.com/authorize/identity",
"IAMGetUserUrl": "https://idm-client-test.us-east.philips-healthsuite.com/authorize/identity/User?profileType=membership&userId=",
"CDRBaseUrl": "https://cdr-edisa-test.us-east.philips-healthsuite.com",
"OauthClientID": "auto-mfpbc",
"OauthClientSecret": "",
"CFOrgName": "client-EDI-SolutionAccelerator",
"CFSpaceName": "",
"CFUserName": "solutionaccelerator-cicd-svc",
"CFPassword": "",
"CookieName": "",
"CFOauthTokenUrl": "https://login.cloud.pcftest.com/oauth/token",
"CFBaseUrl": "https://api.cloud.pcftest.com/v3",
"CFAuthenticatorAppName": "authenticator_service",
"APIGatewayBaseUrl": "",
"OauthProxyCookieTimeoutInSeconds": "25",
"AuthenticatorSessionExpireOffsetInPercent": "99",
"AccessTokenTestRoleName": "TESTROLE",
"OpenIdConfigurationBaseUrl": "https://foundation-client-test.us-east.philips-healthsuite.com",
"OpenIdConfigOrganizationCertificateMapping": "",
"TenantDetails": ""
}
}

View File

@ -1,34 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>$id$</id>
<version>$version$</version>
<title />
<authors>Philips EDI Foundation APIGateway Automation</authors>
<owners />
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>""</description>
<dependencies>
<group targetFramework="netcoreapp3.1" />
</dependencies>
</metadata>
<files>
<file src="**" exclude="*pdb*" target="lib\net3.1\" />
</files>
</package>

View File

@ -1,25 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30225.117
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Philips.EDI.Foundation.APIGateway.AutomationTest", "Philips.EDI.Foundation.APIGateway.AutomationTest.csproj", "{38895658-54E2-47D6-9AF9-552E658FBDDD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{38895658-54E2-47D6-9AF9-552E658FBDDD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{38895658-54E2-47D6-9AF9-552E658FBDDD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{38895658-54E2-47D6-9AF9-552E658FBDDD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{38895658-54E2-47D6-9AF9-552E658FBDDD}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A2BC2EB9-36EE-4105-86F7-2B8ECE632FAD}
EndGlobalSection
EndGlobal

View File

@ -1,70 +0,0 @@
# API Gateway Automation
## Pre-Condition
Mountebank application should be deployed along with API Gateway deployment.
Mountebank deployment with terrform: https://github.com/philips-internal/hds-auth-gateway/blob/master/Automation/deploy/cloud/app_monteback.tf
Allow Injection command should be passed while starting the mountebank application
command = "node bin/mb --allowInjection"
PostDeploymentTest has to executed first in order to create less payload and heavy payload mockservices for automation.
(TestCategory = PostDeployment)
Mockservice configuration files https://github.com/philips-internal/hds-auth-gateway/tree/master/AutomationTest/Tests/Data/MockServiceConfigs
## Automation Configuration
https://github.com/philips-internal/hds-auth-gateway/blob/master/AutomationTest/Env.json
AppConfiguration section is for static confguration values and drive name can be changed from C:\ to other drive for automation word reports and screenshots.
"AppConfiguration": { }
PipelineConfiguration section is for dynamic configuration which will be filled from tfs pipeline or user can fill before executing the automation.
"PipelineConfiguration": { }
| Key | Description | Type |
| --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- |
| AuthUserName | IAM login user email address, For browser based login tests and also for access token authenticator tests | String |
| AuthPassword | IAM login password | String |
| APIGatewayBaseUrl | BaseUrl fo the API gateway <br/>Examples:<br/>For Cloud: https://covid-ver2-api-gateway.us-east.philips-healthsuite.com<br/>For On-Prem: https://localhost (or) https://hostname | String |
| OauthProxyCookieTimeoutInSeconds | Oauth proxy cookie time out in seconds ( default value: 15 ) | Integer |
| TenantDetails | Tenant information with user-friendly tenant sub-domain name and its relevant Iam organization-ID. <br/>Default Values:<br/>"ValidTenant":{"tenantName":"","iamOrganizationId":""}<br>"InvalidTenant":{"tenantName":"invalidtenant","iamOrganizationId":""}<br>"AccessTokenTenant":{"tenantName":"accesstokentenant","iamOrganizationId":""} | String |
| OauthClientID | IAM Oauth client id or User name. Used to get the Authorization Basic token, which will be used to get User or ServiceId Access token. | String |
| OauthClientSecret | IAM Oauth client password | String |
| CFSpaceName | Cloud foundry space name where the api gateway is deployed | String |
| CFUserName | Cloud foundry user name | String |
| CFPassword | Cloud foundry user password | String |
| CookieName | OAuth2 Proxy cookie name | String |
| CFLoginUrl | Cloud foundry login url (default: https://login.cloud.pcftest.com/oauth/token) | String |
| CFAppsUrl | Cloud foundry apps url (default: https://api.cloud.pcftest.com/v3/apps) | String |
| CFAuthenticatorAppName | Token Authenticator internal app name deployed in the space | String |
| AuthenticatorSessionExpireOffsetInPercent | Redis cache clear timeout offset for Authenticator app (default: 10), eg: if set to 99, then Redis cache will get cleared in 18 seconds ( if IAM access token timeout: 30 minutes) | String |
| ServiceID | Service identities ID in IAM | String |
| ServiceIDPrivateKey | ServiceID's private key in IAM | String |
| IDMClientBaseUrl | IDM client url till identiry (eg: https://idm-client-test.us-east.philips-healthsuite.com/authorize/identity) IAM | String |
String |
| IAMAuthorizationUrl | IAM client authorization url (eg: https://iam-client-test.us-east.philips-healthsuite.com/authorize/oauth2/token) IAM | String |
| IAMAccessTokenUrl | IAM client access token url (eg: https://iam-client-test.us-east.philips-healthsuite.com/oauth2/access_token) IAM | String |
| AccessTokenTestRoleName | Role with BASIC.READ permission created for an organization ( eg: RoleName: TESTROLE ) which is used for access token authenticator tests | String |
## Automation Test categories and corresponding Envoy configuration files to deploy
| TestCategory | Envoy file | Comments |
| --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- |
| WithoutMultitenancy | https://github.com/philips-internal/hds-auth-gateway/tree/master/AutomationTest/Tests/Data/EnvoyConfigs/envoyconfig_without_multitenancy.yaml | With Standalone Redis |
| OrgNameInUrl | https://github.com/philips-internal/hds-auth-gateway/tree/master/AutomationTest/Tests/Data/EnvoyConfigs/envoyconfig_with_multitenancy.yaml | With Standalone Redis and APIGateway environment variable ORG_ID_SOURCE="url" |
| OrgIdInHeader | https://github.com/philips-internal/hds-auth-gateway/tree/master/AutomationTest/Tests/Data/EnvoyConfigs/envoyconfig_with_multitenancy.yaml | With Cluster Redis and APIGateway environment variable ORG_ID_SOURCE="header" |
| UserAccessToken | https://github.com/philips-internal/hds-auth-gateway/tree/master/AutomationTest/Tests/Data/EnvoyConfigs/envoyconfig_withoutMultitenancy_WithAuthenticator.yaml | With Standalone Redis" |
| ServiceIDAccessToken | https://github.com/philips-internal/hds-auth-gateway/tree/master/AutomationTest/Tests/Data/EnvoyConfigs/envoyconfig_withoutMultitenancy_WithAuthenticator.yaml | With Standalone Redis" |
## Automation Test Reports
Automation test reports will be available as word report and trx report file which is interated with tfs release pipeline and displayed in test results dashboard.
https://tfsemea1.ta.philips.com/tfs/TPC_Region11/SAL/_dashboards/dashboard/76acadfe-3e1f-4225-9f4f-19af794bc95f
## Manual Test cases suite:
https://tfsemea1.ta.philips.com/tfs/TPC_Region11/Healthcare%20IT/_testPlans/define?planId=1297712&suiteId=1298021

View File

@ -1,532 +0,0 @@
using System;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json.Linq;
using Philips.EDI.Foundation.APIGateway.AutomationTest.Models;
using Philips.EDI.Foundation.APIGateway.AutomationTest.Tests.Common;
using Philips.EDI.Foundation.APIGateway.AutomationTest.Utilities;
using Philips.EDI.Foundation.APIGateway.AutomationTest.BusinessLayer;
using Philips.EDI.Foundation.APIGateway.AutomationTest.CFUtilites;
using Philips.EDI.Foundation.APIGateway.AutomationTest.CFUtilites.Models;
using Reporters;
using Utilities;
using Utilities.Wait;
using System.Threading.Tasks;
namespace Philips.EDI.Foundation.APIGateway.AutomationTest.Tests.APITests.AccessTokenAuthenticationTests
{
[TestClass]
public class AccessTokenAuthenticationTests : BaseTest
{
private readonly CFUtility _cfUtility = new CFUtility(pipelineConfigs.CFBaseUrl, pipelineConfigs.CFUserName, pipelineConfigs.CFPassword, pipelineConfigs.CFOauthTokenUrl);
private readonly HSPIAMBusinessLayer _iamBL = new HSPIAMBusinessLayer();
private const string _permission = "BASIC.READ";
private static string _permissionsJson = "{\"permissions\":[\"PermissionPlaceHolder\"]}".Replace("PermissionPlaceHolder", _permission);
[TestCategory(nameof(TestCategory.GatedSanity))]
[TestCategory(nameof(TestCategory.Nightly))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.UserAccessToken))]
[TestCategory(nameof(TestCategory.OnPrem))]
[TestMethod]
public void APIGetCallWithUserAccessTokenTest()
{
var userAccessTokenHeader = CreateUserAccessTokenHeader();
APIGetCallWithAccessToken(userAccessTokenHeader);
}
[TestCategory(nameof(TestCategory.GatedSanity))]
[TestCategory(nameof(TestCategory.Nightly))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.UserAccessToken))]
[TestCategory(nameof(TestCategory.OnPrem))]
[TestMethod]
public void APICallsWithMultipleUserAccessTokenAndVerifySpecificAccessTokenIntrospectValueTest()
{
var userAccessTokenHeader1 = CreateUserAccessTokenHeader();
var userAccessTokenHeader2 = CreateUserAccessTokenHeader();
var userAccessTokenHeader3 = CreateUserAccessTokenHeader();
var userAccessTokenHeader4 = CreateUserAccessTokenHeader();
var userAccessTokenHeader5 = CreateUserAccessTokenHeader();
APICallsWithMultipleAccessTokenAndVerifySpecificAccessTokenIntrospectValue(userAccessTokenHeader1, userAccessTokenHeader2, userAccessTokenHeader3, userAccessTokenHeader4, userAccessTokenHeader5);
}
[TestCategory(nameof(TestCategory.GatedSanity))]
[TestCategory(nameof(TestCategory.Nightly))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.UserAccessToken))]
[TestCategory(nameof(TestCategory.OnPrem))]
[TestMethod]
public void CRUDApiCallWithUserAccessTokenTest()
{
var userAccessTokenHeader = CreateUserAccessTokenHeader();
CRUDApiCallWithAccessToken(userAccessTokenHeader);
}
[TestCategory(nameof(TestCategory.Nightly))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.UserAccessToken))]
[TestCategory(nameof(TestCategory.OnPrem))]
[TestMethod]
public void APIGetCallWithInvalidAccessTokenTest()
{
Report.Step(@"API call with access token", @"Should get the 401 Unauthorized response");
var invalidAccessTokenHeader = new Dictionary<string, string>();
invalidAccessTokenHeader.Add("Authorization", $"Bearer {Guid.NewGuid().ToString()}");
var response = HttpClientUtility.ExecuteAsync(HttpMethod.Get, defaultEndpointUrl, invalidAccessTokenHeader, null).Result;
AssertTest.IsTrue(response.StatusCode == HttpStatusCode.Unauthorized, failMsg: "Not received HttpStatusCode.Unauthorized", passMsg: "Received HttpStatusCode.Unauthorized");
}
[TestCategory(nameof(TestCategory.GatedSanity))]
[TestCategory(nameof(TestCategory.Nightly))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.UserAccessToken))]
[TestCategory(nameof(TestCategory.OnPrem))]
[TestMethod]
public void APIGetCallWithRefreshTokenTest()
{
Report.Step(@"API call with refresh token", @"Should get the 401 Unauthorized response");
var userAccessTokenHeader = CreateUserAccessTokenHeader("refresh_token");
var response = HttpClientUtility.ExecuteAsync(HttpMethod.Get, defaultEndpointUrl, userAccessTokenHeader, null).Result;
AssertTest.IsTrue(response.StatusCode == HttpStatusCode.Unauthorized, failMsg: "Not received HttpStatusCode.Unauthorized", passMsg: "Received HttpStatusCode.Unauthorized");
}
[TestCategory(nameof(TestCategory.Nightly))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.UserAccessToken))]
[TestCategory(nameof(TestCategory.OnPrem))]
[TestMethod]
public void ChangePermissionInRoleAndVerifyUserAccessTokenPermissionsBeforeRedisCacheTimeoutTest()
{
var userAccessTokenHeader = CreateUserAccessTokenHeader();
AddPermissionInRole(userAccessTokenHeader, _permission);
ChangePermissionInRoleAndVerifyAccessTokenPermissionsBeforeRedisCacheTimeoutTest(userAccessTokenHeader, _permission);
}
[TestCategory(nameof(TestCategory.Nightly))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.UserAccessToken))]
[TestMethod]
public void ChangePermissionInRoleAndVerifyUserAccessTokenPermissionsAfterRedisCacheTimeoutTest()
{
//By default Authenticator_session__SessionExpireOffsetInPercent is 10% and updating to 99%, so that the redis cache will clear in 18 seconds
var userAccessTokenHeader = CreateUserAccessTokenHeader();
AddPermissionInRole(userAccessTokenHeader, _permission);
ChangePermissionInRoleAndVerifyAccessTokenPermissionsAfterRedisCacheTimeoutTest(userAccessTokenHeader, _permission);
}
[TestCategory(nameof(TestCategory.Nightly))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.UserAccessToken))]
[TestCategory(nameof(TestCategory.OnPrem))]
[TestMethod]
public void APIGetCallWithUserAccessTokenWithNoPermissionTest()
{
var accessTokenHeader = CreateUserAccessTokenHeader();
APIGetCallWithAccessTokenWithNoPermission(accessTokenHeader);
}
[TestCategory(nameof(TestCategory.Nightly))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.UserAccessToken))]
[TestMethod]
public void StopAccessTokenAuthenticatorAppAndMakeAPICallWithUserAccessTokenTest()
{
var userAccessTokenHeader = CreateUserAccessTokenHeader();
StopAccessTokenAuthenticatorAppAndMakeAPICallWithAccessTokenTest(userAccessTokenHeader);
}
[TestCategory(nameof(TestCategory.GatedSanity))]
[TestCategory(nameof(TestCategory.Nightly))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.ServiceIDAccessToken))]
[TestCategory(nameof(TestCategory.OnPrem))]
[TestMethod]
public void APIGetCallWithServiceIDAccessTokenTest()
{
var serviceIDAccessTokenHeader = CreateServiceIDAccessTokenHeader();
APIGetCallWithAccessToken(serviceIDAccessTokenHeader);
}
[TestCategory(nameof(TestCategory.GatedSanity))]
[TestCategory(nameof(TestCategory.Nightly))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.ServiceIDAccessToken))]
[TestCategory(nameof(TestCategory.OnPrem))]
[TestMethod]
public void CRUDApiCallWithServiceIDAccessTokenTest()
{
var serviceIDAccessTokenHeader = CreateServiceIDAccessTokenHeader();
CRUDApiCallWithAccessToken(serviceIDAccessTokenHeader);
}
[TestCategory(nameof(TestCategory.GatedSanity))]
[TestCategory(nameof(TestCategory.Nightly))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.ServiceIDAccessToken))]
[TestCategory(nameof(TestCategory.OnPrem))]
[TestMethod]
public void APICallsWithMultipleServiceIDAccessTokenAndVerifySpecificAccessTokenIntrospectValueTest()
{
var serviceIDAccessTokenHeader1 = CreateServiceIDAccessTokenHeader();
var serviceIDAccessTokenHeader2 = CreateServiceIDAccessTokenHeader();
var serviceIDAccessTokenHeader3 = CreateServiceIDAccessTokenHeader();
var serviceIDAccessTokenHeader4 = CreateServiceIDAccessTokenHeader();
var serviceIDAccessTokenHeader5 = CreateServiceIDAccessTokenHeader();
APICallsWithMultipleAccessTokenAndVerifySpecificAccessTokenIntrospectValue(serviceIDAccessTokenHeader1, serviceIDAccessTokenHeader2, serviceIDAccessTokenHeader3, serviceIDAccessTokenHeader4, serviceIDAccessTokenHeader5);
}
[TestCategory(nameof(TestCategory.Nightly))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.ServiceIDAccessToken))]
[TestCategory(nameof(TestCategory.OnPrem))]
[TestMethod]
public void ChangePermissionInRoleAndVerifyServiceIDAccessTokenPermissionsBeforeRedisCacheTimeoutTest()
{
var serviceIDAccessTokenHeader = CreateServiceIDAccessTokenHeader();
AddPermissionInRole(serviceIDAccessTokenHeader, _permission);
ChangePermissionInRoleAndVerifyAccessTokenPermissionsBeforeRedisCacheTimeoutTest(serviceIDAccessTokenHeader, _permission);
}
[TestCategory(nameof(TestCategory.Nightly))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.ServiceIDAccessToken))]
[TestMethod]
public void ChangePermissionInRoleAndVerifyServiceIDAccessTokenPermissionsAfterRedisCacheTimeoutTest()
{
//By default Authenticator_session__SessionExpireOffsetInPercent is 10% and updating to 99%, so that the redis cache will clear in 18 seconds
var serviceIDAccessTokenHeader = CreateServiceIDAccessTokenHeader();
AddPermissionInRole(serviceIDAccessTokenHeader, _permission);
ChangePermissionInRoleAndVerifyAccessTokenPermissionsAfterRedisCacheTimeoutTest(serviceIDAccessTokenHeader, _permission);
}
[TestCategory(nameof(TestCategory.GatedSanity))]
[TestCategory(nameof(TestCategory.Nightly))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.ServiceIDAccessToken))]
[TestCategory(nameof(TestCategory.OnPrem))]
[TestMethod]
public void APIGetCallWithServiceIDAccessTokenWithNoPermissionTest()
{
var accessTokenHeader = CreateServiceIDAccessTokenHeader();
APIGetCallWithAccessTokenWithNoPermission(accessTokenHeader);
}
[TestCategory(nameof(TestCategory.Nightly))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.ServiceIDAccessToken))]
[TestMethod]
public void StopAccessTokenAuthenticatorAppAndMakeAPICallWithServiceIDAccessTokenTest()
{
var serviceIDAccessTokenHeader = CreateServiceIDAccessTokenHeader();
StopAccessTokenAuthenticatorAppAndMakeAPICallWithAccessTokenTest(serviceIDAccessTokenHeader);
}
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestMethod]
public async Task HttpToHttpsRedirectionUsingAPIGatewayTest()
{
var apiGatewayUrl = pipelineConfigs.APIGatewayBaseUrl.Replace("https","http");
AssertTest.IsFalse(apiGatewayUrl.Contains("https"), failMsg: "Invalid Url", passMsg: "Valid Url");
var userAccessTokenHeader = CreateUserAccessTokenHeader();
var response = await HttpClientUtility.ExecuteAsyncWithoutHttpRedirection(HttpMethod.Get,apiGatewayUrl+appConfigs.LessPayloadMockservice, userAccessTokenHeader,null);
Assert.AreEqual(HttpStatusCode.MovedPermanently, response.StatusCode);
var redirectedUrl = response.Headers.Location.AbsoluteUri;
var redirectedResponse = HttpClientUtility.ExecuteAndGetResponse(response.RequestMessage.Method, redirectedUrl, userAccessTokenHeader, null);
AssertTest.IsTrue(redirectedResponse != null && redirectedResponse["status"].ToString().EqualsWithIgnoreCase("success"), failMsg: "No Success response received", passMsg: "Received success response");
}
#region Private methods
private void APIGetCallWithAccessToken(Dictionary<string, string> accessTokenHeader)
{
Report.Step(@"API call with access token", @"Should get the valid upstream response");
var responseBody = HttpClientUtility.ExecuteAndGetResponse(HttpMethod.Get, defaultEndpointUrl, accessTokenHeader, null);
AssertTest.IsTrue(responseBody != null && responseBody["status"].ToString().EqualsWithIgnoreCase("success"), failMsg: "No Success response received", passMsg: "Received success response");
}
private void CRUDApiCallWithAccessToken(Dictionary<string, string> accessTokenHeader)
{
Report.Step(@"GET API call with access token", @"Should get the valid upstream response");
var getResponseBody = HttpClientUtility.ExecuteAndGetResponse(HttpMethod.Get, defaultEndpointUrl, accessTokenHeader, null);
AssertTest.IsTrue(getResponseBody != null && getResponseBody["status"].ToString().EqualsWithIgnoreCase("success"), failMsg: "No Success response received", passMsg: "Received success response");
Report.Step(@"POST API call with access token", @"Should post successfully");
var content = HttpClientUtility.CreateHttpContent(getResponseBody.ToString());
var postResponse = HttpClientUtility.ExecuteAndGetResponse(HttpMethod.Post, defaultEndpointUrl, accessTokenHeader, content);
AssertTest.IsTrue(postResponse != null && postResponse["status"].ToString().EqualsWithIgnoreCase("success"), failMsg: "No Success response received", passMsg: "Received success response");
Report.Step(@"PUT API call with access token", @"Should update successfully");
string _heavyPayloadMockServiceUrl = $"{pipelineConfigs.APIGatewayBaseUrl}{ appConfigs.HeavyPayloadMockservice}";
getResponseBody = HttpClientUtility.ExecuteAndGetResponse(HttpMethod.Get, _heavyPayloadMockServiceUrl, accessTokenHeader, null);
content = HttpClientUtility.CreateHttpContent(getResponseBody.ToString());
var putResponse = HttpClientUtility.ExecuteAndGetResponse(HttpMethod.Put, defaultEndpointUrl, accessTokenHeader, content);
AssertTest.IsTrue(putResponse != null && putResponse["status"].ToString().EqualsWithIgnoreCase("success"), failMsg: "No Success response received", passMsg: "Received success response");
Report.Step(@"DELETE API call with access token", @"Should delete successfully");
var deleteResponse = HttpClientUtility.ExecuteAndGetResponse(HttpMethod.Delete, _heavyPayloadMockServiceUrl, accessTokenHeader, null);
AssertTest.IsTrue(deleteResponse != null && deleteResponse["status"].ToString().EqualsWithIgnoreCase("success"), failMsg: "No Success response received", passMsg: "Received success response");
}
private void ChangePermissionInRoleAndVerifyAccessTokenPermissionsBeforeRedisCacheTimeoutTest(Dictionary<string, string> accessTokenHeader, string permission)
{
try
{
APIGetCallAndRemoveAccessTokenPermissionInRole(accessTokenHeader, permission);
List<JToken> permissionsFromIntrospectValue = APICallAndGetPermissionsFromIntrospectValue(accessTokenHeader);
Report.Step(@"Access token permissions should not change before redis cache timeout",
@"The permissions should not be changed");
AssertTest.IsTrue(permissionsFromIntrospectValue.Contains(permission), failMsg: $"Permission: {permission} removed is updated in redis cache", passMsg: $"Permission: {permission} removed is not updated in redis cache");
}
catch (Exception ex)
{
Logger.InfoFailedWithException(ex);
throw;
}
finally
{
AddPermissionInRole(accessTokenHeader, permission);
}
}
private void ChangePermissionInRoleAndVerifyAccessTokenPermissionsAfterRedisCacheTimeoutTest(Dictionary<string, string> userAccessTokenHeader, string permission)
{
Report.Step($"Create/Update the Environment variable Authenticator_session__SessionExpireOffsetInPercent={pipelineConfigs.AuthenticatorSessionExpireOffsetInPercent}, for access token authenticator application in CF",
@"Environment variable should get created/updated");
var response = _cfUtility.UpdateEnvironmentVariablesToCFApp(pipelineConfigs.CFOrgName, pipelineConfigs.CFSpaceName, pipelineConfigs.CFAuthenticatorAppName,
new Dictionary<string, string> { { Constants.AuthenticatorSessionExpireOffsetInPercent, pipelineConfigs.AuthenticatorSessionExpireOffsetInPercent } });
AssertTest.IsTrue(response[Constants.AuthenticatorSessionExpireOffsetInPercent] == pipelineConfigs.AuthenticatorSessionExpireOffsetInPercent, failMsg: "Env variable create/update failed", passMsg: "Env variable created/updated successfully");
try
{
APIGetCallAndRemoveAccessTokenPermissionInRole(userAccessTokenHeader, permission);
//IAM Access Token timeout 30min (1800 seconds)
int cacheClearWaitTimeInSeconds = (int)Math.Round(1800 - (1800 * (Convert.ToDouble(pipelineConfigs.AuthenticatorSessionExpireOffsetInPercent) / 100)));
cacheClearWaitTimeInSeconds += 10; //(10 seconds buffer)
Report.Step($"Wait for { cacheClearWaitTimeInSeconds} seconds to get Redis cache clear", "");
Sleep.Seconds(cacheClearWaitTimeInSeconds);
var permissionsFromIntrospectValue = APICallAndGetPermissionsFromIntrospectValue(userAccessTokenHeader);
Report.Step(@"Access token permissions should change after redis cache timeout",
@"The permissions should be changed");
AssertTest.IsTrue(!permissionsFromIntrospectValue.Contains(permission), failMsg: $"Permission: {permission} removed, is not updated in redis cache", passMsg: $"Permission: { permission} removed, is updated in redis cache");
}
catch (Exception ex)
{
Logger.InfoFailedWithException(ex);
throw;
}
finally
{
Report.Step("Executing the Finally Block", "Finally Block should get executed");
AddPermissionInRole(userAccessTokenHeader, permission);
_cfUtility.UpdateEnvironmentVariablesToCFApp(pipelineConfigs.CFOrgName, pipelineConfigs.CFSpaceName, pipelineConfigs.CFAuthenticatorAppName,
new Dictionary<string, string> { { Constants.AuthenticatorSessionExpireOffsetInPercent, "10" } });
}
}
private void StopAccessTokenAuthenticatorAppAndMakeAPICallWithAccessTokenTest(Dictionary<string, string> userAccessTokenHeader)
{
Report.Step(@"Stop the access token authenticator application", @"Access token authenticator application should be stopped");
AssertTest.IsTrue(_cfUtility.ChangingCFAppState(pipelineConfigs.CFOrgName, pipelineConfigs.CFSpaceName, pipelineConfigs.CFAuthenticatorAppName, AppState.stop), failMsg: "Failed to stop application", passMsg: "Application stopped successfully");
try
{
Report.Step(@"API call with access token", @"Should get the 403 forbidden response");
var response = HttpClientUtility.ExecuteAsync(HttpMethod.Get, defaultEndpointUrl, userAccessTokenHeader, null).Result;
AssertTest.IsTrue(response.StatusCode == HttpStatusCode.Forbidden, failMsg: $"Failed to get 403 Forbidden status code, Actual: {response.StatusCode}", passMsg: "Recieved 403 Forbidden status code");
}
catch (Exception ex)
{
Logger.InfoFailedWithException(ex);
throw;
}
finally
{
Report.Step(@"Start the access token authenticator application", @"Access token authenticator application should be started");
AssertTest.IsTrue(_cfUtility.ChangingCFAppState(pipelineConfigs.CFOrgName, pipelineConfigs.CFSpaceName, pipelineConfigs.CFAuthenticatorAppName, AppState.start), failMsg: "Failed to start application", passMsg: "Application started successfully");
}
}
private List<JToken> APICallAndGetPermissionsFromIntrospectValue(Dictionary<string, string> userAccessTokenHeader)
{
Report.Step(@"Another API call with the same access token", @"Should get the valid upstream response");
string customUniqueRequestHeaderValue = Guid.NewGuid().ToString();
userAccessTokenHeader.Add(Constants.CustomUniqueRequestHeaderName, customUniqueRequestHeaderValue);
var responseBody = HttpClientUtility.ExecuteAndGetResponse(HttpMethod.Get, defaultEndpointUrl, userAccessTokenHeader, null);
AssertTest.IsTrue(responseBody != null && responseBody["status"].ToString().EqualsWithIgnoreCase("success"), failMsg: "No Success response received", passMsg: "Received success response");
Report.Step(@"Get the recorded upstream call request from mountebank mockservice",
@"edisp-introspect-value should be available in the upstream request headers");
CommonBL commonBL = new CommonBL();
var getResponseBody = commonBL.GetImposterRecordedRequests(pipelineConfigs.APIGatewayBaseUrl, userAccessTokenHeader, "LessPayloadMockservice.json");
var headers = getResponseBody["requests"].Where(x => x["headers"][Constants.CustomUniqueRequestHeaderName] != null && x["headers"][Constants.CustomUniqueRequestHeaderName].ToString() == customUniqueRequestHeaderValue).FirstOrDefault();
var introspectEncodedValue = headers["headers"]["edisp-introspect-value"].ToString();
AssertTest.IsTrue(!string.IsNullOrWhiteSpace(introspectEncodedValue), failMsg: "edisp-introspect-value is not found in upstream request headers", passMsg: "edisp-introspect-value is available in upstream request headers");
byte[] data = Convert.FromBase64String(introspectEncodedValue);
string decodedString = Encoding.UTF8.GetString(data);
var permissionsFromIntrospectValue = JObject.Parse(decodedString)["organizations"]["organizationList"].Where(x => x["organizationId"].ToString() == tenantDetails[Constants.AccessTokenTenantKey].IamOrganizationId).FirstOrDefault()["permissions"].ToList();
return permissionsFromIntrospectValue;
}
private void APIGetCallAndRemoveAccessTokenPermissionInRole(Dictionary<string, string> accessTokenHeader, string permission)
{
Report.Step(@"API call with access token", @"Should get the valid upstream response");
if (accessTokenHeader.ContainsKey("api-version"))
accessTokenHeader.Remove("api-version");
var responseBody = HttpClientUtility.ExecuteAndGetResponse(HttpMethod.Get, defaultEndpointUrl, accessTokenHeader, null);
AssertTest.IsTrue(responseBody != null && responseBody["status"].ToString().EqualsWithIgnoreCase("success"), failMsg: $"No Success response received, Response Body: '{responseBody}'", passMsg: "Received success response");
RemovePermissionInRole(accessTokenHeader, permission);
}
private bool RemovePermissionInRole(Dictionary<string, string> accessTokenHeader, string permission)
{
Report.Step(@"Capture persmissions from Role in IAM for the access token", @"Should get all the permissions captured from Role in IAM");
string roleId = _iamBL.GetRoleId(pipelineConfigs.IDMClientBaseUrl, accessTokenHeader, tenantDetails[Constants.AccessTokenTenantKey].IamOrganizationId, pipelineConfigs.AccessTokenTestRoleName);
List<string> capturedAllPermissions = _iamBL.GetAllPersmissionsFromRole(pipelineConfigs.IDMClientBaseUrl, accessTokenHeader, roleId);
AssertTest.IsTrue(capturedAllPermissions.Count > 0, failMsg: "No permission catpured from role", passMsg: "Captured all persmission from role");
if (capturedAllPermissions.Contains(permission))
{
Report.Step(@"Remove permissions in Role", @"Permissions should be removed in the Role");
_iamBL.RemovePermissionFromRole(pipelineConfigs.IDMClientBaseUrl, accessTokenHeader, roleId, _permissionsJson);
Logger.Info($"Remove Permission: {permission}");
bool isPermissionRemoved = !_iamBL.GetAllPersmissionsFromRole(pipelineConfigs.IDMClientBaseUrl, accessTokenHeader, roleId).Contains(permission);
AssertTest.IsTrue(isPermissionRemoved, failMsg: $"Permission: {permission} not removed", passMsg: $"Permission: {permission} removed successfully");
return isPermissionRemoved;
}
else
{
AssertTest.IsTrue(!capturedAllPermissions.Contains(permission), failMsg: $"Permission: {permission} exist ", passMsg: $"Permission: {permission} already not exists");
return true;
}
}
private bool AddPermissionInRole(Dictionary<string, string> accessTokenHeader, string permission)
{
Report.Step(@"Capture persmissions from Role in IAM for the access token", @"Should get all the permissions captured from Role in IAM");
string roleId = _iamBL.GetRoleId(pipelineConfigs.IDMClientBaseUrl, accessTokenHeader, tenantDetails[Constants.AccessTokenTenantKey].IamOrganizationId, pipelineConfigs.AccessTokenTestRoleName);
List<string> capturedAllPermissions = _iamBL.GetAllPersmissionsFromRole(pipelineConfigs.IDMClientBaseUrl, accessTokenHeader, roleId);
AssertTest.IsTrue(capturedAllPermissions.Count > 0, failMsg: "No permission catpured from role", passMsg: "Captured all persmission from role");
Report.Step(@"Add permissions in Role", @"Permissions should be added in the Role");
if (!capturedAllPermissions.Contains(permission))
{
_iamBL.AssignPermissionToRole(pipelineConfigs.IDMClientBaseUrl, accessTokenHeader, roleId, _permissionsJson);
Logger.Info($"Assigned Permission: {permission}");
bool isPermssionAdded = _iamBL.GetAllPersmissionsFromRole(pipelineConfigs.IDMClientBaseUrl, accessTokenHeader, roleId).Contains(permission);
AssertTest.IsTrue(isPermssionAdded, failMsg: $"Permission: {permission} not added", passMsg: $"Permission: {permission} added successfully");
return isPermssionAdded;
}
else
{
AssertTest.IsTrue(capturedAllPermissions.Contains(permission), failMsg: $"Permission: {permission} not exist", passMsg: $"Permission: {permission} already exists");
return true;
}
}
private Dictionary<string, string> CreateUserAccessTokenHeader(string tokenType = "access_token")
{
var userAccessTokenHeader = HttpClientUtility.CreateUserAccessTokenHeader(pipelineConfigs,tokenType);
AssertTest.IsTrue(userAccessTokenHeader != null, failMsg: "User Access Token header is null", passMsg: $"User Access Token header is not null");
return userAccessTokenHeader;
}
private Dictionary<string, string> CreateServiceIDAccessTokenHeader()
{
var serviceIDAccessTokenHeader = HttpClientUtility.CreateServiceIdAccessTokenHeader(pipelineConfigs);
AssertTest.IsTrue(serviceIDAccessTokenHeader != null, failMsg: "ServiceID Access Token header is null", passMsg: $"ServiceID Access Token header is not null:{serviceIDAccessTokenHeader}");
return serviceIDAccessTokenHeader;
}
private void APIGetCallWithAccessTokenWithNoPermission(Dictionary<string, string> accessTokenHeader)
{
Report.Step(@"Check and remove permissions in Role if exists", @"Permissions should be remove if exist in the Role");
HSPIAMBusinessLayer iamBL = new HSPIAMBusinessLayer();
string roleId = iamBL.GetRoleId(pipelineConfigs.IDMClientBaseUrl, accessTokenHeader, tenantDetails[Constants.AccessTokenTenantKey].IamOrganizationId, pipelineConfigs.AccessTokenTestRoleName);
var allPermissions = iamBL.GetAllPersmissionsFromRole(pipelineConfigs.IDMClientBaseUrl, accessTokenHeader, roleId);
if (allPermissions.Contains(_permission))
{
bool permissionRemovedStatus = iamBL.RemovePermissionFromRole(pipelineConfigs.IDMClientBaseUrl, accessTokenHeader, roleId, _permissionsJson);
AssertTest.IsTrue(permissionRemovedStatus, failMsg: "Failed to removed the permission {_permission} in role", passMsg: $"Removed permission {_permission} in role");
}
Report.Step(@"API call with access token", @"Should get the 403 Forbidden response");
string checkPermissionMockserviceUrl = $"{defaultEndpointUrl}/checkpermission";
accessTokenHeader.Add("edisp-org-id", tenantDetails[Constants.AccessTokenTenantKey].IamOrganizationId);
accessTokenHeader.Add("permission-name", _permission);
var response = HttpClientUtility.ExecuteAsync(HttpMethod.Get, checkPermissionMockserviceUrl, accessTokenHeader, null).Result;
AssertTest.IsTrue(response.StatusCode == HttpStatusCode.Forbidden, failMsg: $"Did not receive 403 Forbidden response, Actual: {response.StatusCode}", passMsg: "Received 403 Forbidden response");
}
private void APICallsWithMultipleAccessTokenAndVerifySpecificAccessTokenIntrospectValue(Dictionary<string, string> accessTokenHeader1, Dictionary<string, string> accessTokenHeader2, Dictionary<string, string> accessTokenHeader3, Dictionary<string, string> userAccessTokenHeader4, Dictionary<string, string> userAccessTokenHeader5)
{
AddPermissionInRole(accessTokenHeader1, _permission);
Report.Step(@"2 API calls with first 2 different access token", @"Should get the valid upstream response for all 2 api calls");
APIGetCallWithAccessToken(accessTokenHeader1);
APIGetCallWithAccessToken(accessTokenHeader2);
Report.Step(@"Remove permission with the access token", @"Permissions should be removed in Role");
RemovePermissionInRole(accessTokenHeader3, _permission);
Sleep.Seconds(3);
Report.Step(@"API call with 3rd access token", @"Should get the valid upstream response for the 3rd api call");
APIGetCallWithAccessToken(accessTokenHeader3);
Report.Step(@"Revert the permission which earlier did with access token", @"Permissions should be reverted in Role");
RemovePermissionInRole(accessTokenHeader3, _permission);
Report.Step(@"API calls with last 2 access token", @"Should get the valid upstream response for the last 2 api calls");
APIGetCallWithAccessToken(userAccessTokenHeader4);
APIGetCallWithAccessToken(userAccessTokenHeader5);
var introspectValuePermissions = APICallAndGetPermissionsFromIntrospectValue(accessTokenHeader3);
Report.Step(@"Should get the correct introspect value from Redis cache for the given access token",
@"Should get the permission removed introspect value from Redis");
AssertTest.IsTrue(!introspectValuePermissions.Contains(_permission), failMsg: "Failed to get the correct introspect value from Reids", passMsg: "Got the correct introspect value from Reids");
}
#endregion
}
}

View File

@ -1,76 +0,0 @@
using System;
using System.Linq;
using System.Net.Http;
using System.Collections.Generic;
using Driver.UI.Common;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Philips.EDI.Foundation.APIGateway.AutomationTest.BusinessLayer;
using Philips.EDI.Foundation.APIGateway.AutomationTest.Models;
using Philips.EDI.Foundation.APIGateway.AutomationTest.Tests.Common;
using Philips.EDI.Foundation.APIGateway.AutomationTest.Utilities;
using Reporters;
using Utilities;
namespace Philips.EDI.Foundation.APIGateway.AutomationTest.Tests.APITests.IntrospectionTests
{
[TestClass]
public class IntrospectionTests : BaseTest
{
private Cookies _cookie;
private Dictionary<string, string> _headers;
[TestInitialize]
public void BeforeTest()
{
Logger.Info("Before test");
CommonSteps commonSteps = new CommonSteps();
commonSteps.BrowseEndpointAndVerifyLogin(defaultEndpointUrl, pipelineConfigs.AuthUserName, pipelineConfigs.AuthPassword);
Report.Step(@"Get the cookie from browser", @"Should get the valid cookie");
AuthenticationBL authenticationBL = new AuthenticationBL(WebDriver);
_cookie = authenticationBL.GetCookie(pipelineConfigs.CookieName);
_headers = HttpClientUtility.CreateCookieHeader(pipelineConfigs.CookieName, _cookie.CookieValue); ;
AssertTest.IsTrue(_cookie != null, failMsg: "Cookie is not available", passMsg: $"Cookie is available, Cookie value: {_cookie.CookieValue}");
}
[TestCategory(nameof(TestCategory.Nightly))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.OnPrem))]
[TestMethod]
public void IntrospectValueToUpstreamRequestHeaderTest()
{
Report.Step(@"API call to Less payload mockservice and make an imposters api call with mockservice port number to get the recorded upstream request headers from API Gateway",
@"edisp-introspect-value should be available in the upstream request headers");
string customUniqueRequestHeaderValue = Guid.NewGuid().ToString();
_headers.Add(Constants.CustomUniqueRequestHeaderName, customUniqueRequestHeaderValue);
Logger.Info($"Mockservice Url: { defaultEndpointUrl}");
_ = HttpClientUtility.ExecuteAsync(HttpMethod.Get, defaultEndpointUrl, _headers, null);
CommonBL commonBL = new CommonBL();
var getResponseBody = commonBL.GetImposterRecordedRequests(pipelineConfigs.APIGatewayBaseUrl, _headers, "LessPayloadMockservice.json");
var isRecordRequest = (bool)getResponseBody["recordRequests"];
AssertTest.IsTrue(isRecordRequest, failMsg: "Record requests is not enabled in Less payload mockservice imposter", passMsg: "Record request is enabled in Less payload mockservice imposter");
var testHeaderRequest = getResponseBody["requests"].Where(x => x["headers"][Constants.CustomUniqueRequestHeaderName] != null && x["headers"][Constants.CustomUniqueRequestHeaderName].ToString() == customUniqueRequestHeaderValue).FirstOrDefault();
var testHeaderValue = testHeaderRequest["headers"][Constants.CustomUniqueRequestHeaderName].ToString();
var introspectValue = testHeaderRequest["headers"]["edisp-introspect-value"].ToString();
AssertTest.IsTrue(!string.IsNullOrWhiteSpace(testHeaderValue) && !string.IsNullOrWhiteSpace(introspectValue), failMsg: "edisp-introspect-value is not found in upstream request headers", passMsg: "edisp-introspect-value is available in upstream request headers");
}
[TestCategory(nameof(TestCategory.GatedSanity))]
[TestCategory(nameof(TestCategory.Nightly))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.OnPrem))]
[TestMethod]
public void IntrospectValueFromUpstreamResponseHeaderTest()
{
Report.Step(@"GET API call to the CDR service with cookie",
@"edisp-introspect-value should be available in the upstream response headers and Authorization should not be available in the upstream response header");
string cdrServiceUrl = $"{pipelineConfigs.APIGatewayBaseUrl}{appConfigs.CDRSubscriptionUrlPath.Replace("OrgId", tenantDetails[Constants.ValidTenantKey].TenantName)}";
Logger.Info($"CDR service Url: {cdrServiceUrl}");
var response = HttpClientUtility.ExecuteAsync(HttpMethod.Get, cdrServiceUrl, _headers, null).Result;
AssertTest.IsTrue(response != null && response.Headers.Contains("edisp-introspect-value") && !string.IsNullOrWhiteSpace(response.Headers.GetValues("edisp-introspect-value").FirstOrDefault()),
failMsg: "edisp-introspect-value is not found in upstream response headers", passMsg: "edisp-introspect-value is available in upstream request headers");
AssertTest.IsTrue(response != null && !response.Headers.Contains("Authorization"),
failMsg: "'Authorization' header found in upstream response headers", passMsg: "Authorization header is not available in upstream response headers");
}
}
}

View File

@ -1,143 +0,0 @@
using Driver.UI.Common;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Philips.EDI.Foundation.APIGateway.AutomationTest.BusinessLayer;
using Philips.EDI.Foundation.APIGateway.AutomationTest.Models;
using Philips.EDI.Foundation.APIGateway.AutomationTest.Tests.Common;
using Philips.EDI.Foundation.APIGateway.AutomationTest.Utilities;
using Reporters;
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using Utilities;
namespace Philips.EDI.Foundation.APIGateway.AutomationTest.Tests.APITests.MultitenancyStaticConfiguration
{
[TestClass]
public class MultitenancyStaticConfigurationTests : BaseTest
{
private string placeHolderForOrgReplacement;
private Cookies _cookie;
private Dictionary<string, string> _headers;
private static string _apiGatewayBaseUrlWithOrgNamePlaceholder;
private static string _cdrServiceUrlBasePathWithoutOrgId;
private string _cdrSubscriptionUrlWithOrg1;
private string _cdrSubscriptionUrlWithInvalidOrgName;
private string _qidoStudyLevelUrlWithInvalidOrgName;
[TestInitialize]
public void BeforeTest()
{
Logger.Info("Before test");
UriBuilder uriBuilder = new UriBuilder(pipelineConfigs.APIGatewayBaseUrl);
placeHolderForOrgReplacement = $"OrgName-{uriBuilder.Host.Split('.')[0]}";
uriBuilder.Host = $"OrgName-{uriBuilder.Host}";
_apiGatewayBaseUrlWithOrgNamePlaceholder = uriBuilder.Uri.AbsoluteUri;
_cdrServiceUrlBasePathWithoutOrgId = appConfigs.CDRImagingStudyUrlPath.Replace("/OrgId", string.Empty);
_cdrSubscriptionUrlWithOrg1 = $"{_apiGatewayBaseUrlWithOrgNamePlaceholder.Replace(placeHolderForOrgReplacement, tenantDetails[Constants.ValidTenantKey].TenantName, StringComparison.InvariantCultureIgnoreCase)}{_cdrServiceUrlBasePathWithoutOrgId}";
_cdrSubscriptionUrlWithInvalidOrgName = $"{_apiGatewayBaseUrlWithOrgNamePlaceholder.Replace(placeHolderForOrgReplacement, tenantDetails[Constants.InvalidTenantKey].TenantName, StringComparison.InvariantCultureIgnoreCase)}{_cdrServiceUrlBasePathWithoutOrgId}";
_qidoStudyLevelUrlWithInvalidOrgName = $"{_apiGatewayBaseUrlWithOrgNamePlaceholder.Replace(placeHolderForOrgReplacement, tenantDetails[Constants.InvalidTenantKey].TenantName, StringComparison.InvariantCultureIgnoreCase)}{appConfigs.QidoStudyLevelUrlPathWithoutOrgId}";
Report.Step(@"Browse endpoint url and get the cookie from browser", @"Should get the valid cookie");
LoginToEndpoint(_apiGatewayBaseUrlWithOrgNamePlaceholder.Replace(placeHolderForOrgReplacement, tenantDetails[Constants.ValidTenantKey].TenantName, StringComparison.InvariantCultureIgnoreCase), pipelineConfigs.AuthUserName, pipelineConfigs.AuthPassword);
AuthenticationBL authenticationBL = new AuthenticationBL(WebDriver);
_cookie = authenticationBL.GetCookie(pipelineConfigs.CookieName);
_headers = HttpClientUtility.CreateCookieHeader(pipelineConfigs.CookieName, _cookie.CookieValue);
AssertTest.IsTrue(_cookie != null, failMsg: "Cookie is not available", passMsg: $"Cookie is available, Cookie value: {_cookie.CookieValue}");
}
[TestCategory(nameof(TestCategory.OrgNameInUrl))]
[TestMethod]
public void APICallWithValidTenantAsSubDomainTest()
{
Report.Step(@"GET API call to the CDR service with Org Name(org1) as sub domain in Url", @"Should get the valid CDR service response");
CDRGetCallAndAssert(_cdrSubscriptionUrlWithOrg1);
}
[TestCategory(nameof(TestCategory.OrgNameInUrl))]
[TestMethod]
public void APICallWithValidTenantAsSubDomainAndVerifyOrgIdInUpstreamUrlTest()
{
//pathMap= {["/mockserviceA/multitenancy"] = "/mockserviceA/multitenancy/orgId"} should be added in of global lua filter in envoy conifg
Report.Step(@"API call to Less payload mockservice with Org Name (org1) and verify the OrgId in upstream url", @"The upstream url should have org1 orgId");
var customUniqueRequestHeaderValue = Guid.NewGuid().ToString();
_headers.Add(Constants.CustomUniqueRequestHeaderName, customUniqueRequestHeaderValue);
string baseUrl = _apiGatewayBaseUrlWithOrgNamePlaceholder.Replace(placeHolderForOrgReplacement, tenantDetails[Constants.ValidTenantKey].TenantName, StringComparison.InvariantCultureIgnoreCase);
string multitenancyMockserviceUrl = $"{ baseUrl }{ appConfigs.MultitenancyMockservice}";
Logger.Info($"Mockservice Url: {multitenancyMockserviceUrl}");
_ = HttpClientUtility.ExecuteAsync(HttpMethod.Get, multitenancyMockserviceUrl, _headers, null);
CommonBL commonBL = new CommonBL();
_headers.Remove(Constants.CustomUniqueRequestHeaderName);
var upstreamRequestUrl = commonBL.GetUpstreamRecordedRequest(baseUrl, _headers, Constants.CustomUniqueRequestHeaderName, customUniqueRequestHeaderValue, "LessPayloadMockservice.json");
string reqUrl = upstreamRequestUrl["path"].ToString();
Logger.Info($"Upstream request url: { reqUrl}");
AssertTest.IsTrue(upstreamRequestUrl != null && reqUrl.EndsWith(tenantDetails[Constants.ValidTenantKey].IamOrganizationId, StringComparison.InvariantCultureIgnoreCase),
failMsg: $"OrgId is not found in upstream request headers for OrgName: {tenantDetails[Constants.ValidTenantKey].TenantName}", passMsg: $"OrgId is available in upstream request headers for the OrgName: {tenantDetails[Constants.ValidTenantKey].TenantName}");
}
[TestCategory(nameof(TestCategory.OrgNameInUrl))]
[TestMethod]
public void APICallWithInValidTenantAsSubDomainAndOrgNameNotInStaticConfigurationTest()
{
Report.Step(@"GET API call to the CDR service with invalid Org Name as sub domain which is not in static configuration", @"Should get the 404 error response");
Logger.Info($"CDR service invalid org name Url: {_cdrSubscriptionUrlWithInvalidOrgName}");
var response = HttpClientUtility.ExecuteAsync(HttpMethod.Get, _cdrSubscriptionUrlWithInvalidOrgName, _headers, null).Result;
AssertTest.IsTrue(!response.IsSuccessStatusCode && response.StatusCode == HttpStatusCode.NotFound,
failMsg: "Failed to get 404 status code for the CDR service response", passMsg: "Received the 404 status code for the CDR service response");
}
[TestCategory(nameof(TestCategory.OrgNameInUrl))]
[TestMethod]
public void APICallWithInvalidTenantAsSubDomainAndInvalidOrgIdInHeaderTest()
{
Report.Step(@"GET API call to the CDR service with Org Name(org1) as sub domain in Url and invalid OrgId in headers", @"Should get the valid CDR service response");
_headers.Add("edisp-org-id", tenantDetails[Constants.InvalidTenantKey].IamOrganizationId);
Logger.Info($"Invalid OrgId: {tenantDetails[Constants.InvalidTenantKey].IamOrganizationId}");
CDRGetCallAndAssert(_cdrSubscriptionUrlWithOrg1);
}
[TestCategory(nameof(TestCategory.OrgIdInHeader))]
[TestMethod]
public void APICallWithValidOrgIdInHeadersTest()
{
Report.Step(@"GET API call to the CDR service with valid OrgId in header", @"Should get the valid CDR service response");
_headers.Add("edisp-org-id", tenantDetails[Constants.ValidTenantKey].IamOrganizationId);
Logger.Info($"Valid OrgId: {tenantDetails[Constants.ValidTenantKey].TenantName}");
CDRGetCallAndAssert(_cdrSubscriptionUrlWithOrg1);
}
[TestCategory(nameof(TestCategory.OrgIdInHeader))]
[TestMethod]
public void APICallWithInValidOrgIdInHeaderTest()
{
Report.Step(@"GET API call to the dicom service with invalid OrgId in header", @"Should get the 403 error response");
_headers.Add("edisp-org-id", tenantDetails[Constants.InvalidTenantKey].IamOrganizationId);
Logger.Info($"Qido study level Url: {_qidoStudyLevelUrlWithInvalidOrgName}");
var response = HttpClientUtility.ExecuteAsync(HttpMethod.Get, _qidoStudyLevelUrlWithInvalidOrgName, _headers, null).Result;
AssertTest.IsTrue(!response.IsSuccessStatusCode && response.StatusCode == HttpStatusCode.Forbidden,
failMsg: "Failed to get 403 status code in response for the Qido call with invalid OrgId in header", passMsg: "Received the 403 status code response for the qido call with invalid Orgid in header ");
}
[TestCategory(nameof(TestCategory.OrgIdInHeader))]
[TestMethod]
public void APICallWithoutOrgIdInHeaderTest()
{
Report.Step(@"GET API call to the dicom service without OrgId in header", @"Should get the 404 error response");
Logger.Info($"Qido study level Url: {_qidoStudyLevelUrlWithInvalidOrgName}");
var response = HttpClientUtility.ExecuteAsync(HttpMethod.Get, _qidoStudyLevelUrlWithInvalidOrgName, _headers, null).Result;
AssertTest.IsTrue(!response.IsSuccessStatusCode && response.StatusCode == HttpStatusCode.NotFound,
failMsg: "Failed to get 404 status code in response for the Qido call without OrgId in header", passMsg: "Received the 404 status code response for the qido call without Orgid in header ");
}
private void CDRGetCallAndAssert(string _crdSubscriptionUrl)
{
Logger.Info($"CDR subscription Url: {_crdSubscriptionUrl}");
var responseBody = HttpClientUtility.ExecuteAndGetResponse(HttpMethod.Get, _crdSubscriptionUrl, _headers, null);
AssertTest.IsTrue(responseBody != null && responseBody.ContainsKey("resourceType") && responseBody["resourceType"].ToString().EqualsWithIgnoreCase("Bundle"),
failMsg: "Failed to get the CDR service success response", passMsg: "Received the CDR service success response");
}
}
}

View File

@ -1,82 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using Driver.UI.Common;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Philips.EDI.Foundation.APIGateway.AutomationTest.BusinessLayer;
using Philips.EDI.Foundation.APIGateway.AutomationTest.Models;
using Philips.EDI.Foundation.APIGateway.AutomationTest.Tests.Common;
using Philips.EDI.Foundation.APIGateway.AutomationTest.Utilities;
using Reporters;
using Utilities;
namespace Philips.EDI.Foundation.APIGateway.AutomationTest.Tests.APITests.RequestTransformationHeadersTests
{
[TestClass]
public class RequestTransformationHeadersTests : BaseTest
{
private Cookies _cookie;
private Dictionary<string, string> _headers;
[TestInitialize]
public void BeforeTest()
{
Logger.Info("Before test");
CommonSteps _commonSteps = new CommonSteps();
_commonSteps.BrowseEndpointAndVerifyLogin(defaultEndpointUrl, pipelineConfigs.AuthUserName, pipelineConfigs.AuthPassword);
Report.Step(@"Get the cookie from browser", @"Should get the valid cookie");
AuthenticationBL authenticationBL = new AuthenticationBL(WebDriver);
_cookie = authenticationBL.GetCookie(pipelineConfigs.CookieName);
_headers = HttpClientUtility.CreateCookieHeader(pipelineConfigs.CookieName, _cookie.CookieValue);
AssertTest.IsTrue(_cookie != null, failMsg: "Cookie is not available", passMsg: $"Cookie is available, Cookie value: {_cookie.CookieValue}");
}
[TestCategory(nameof(TestCategory.GatedSanity))]
[TestCategory(nameof(TestCategory.Nightly))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.OnPrem))]
[TestMethod]
public void CustomHeaderAddedToUpstreamRequestByAPIGatewayTest()
{
//custom-header:"100" should be added to less payload mockserviceA in envoy config
Report.Step(@"API call to Less payload mockservice and make an imposters api call with mockservice port number to get the recorded upstream request from API Gateway",
@"custom-header should be available in the upstream request headers");
Logger.Info($"Mockservice Url: {defaultEndpointUrl}");
_ = HttpClientUtility.ExecuteAsync(HttpMethod.Get, defaultEndpointUrl, _headers, null);
CommonBL commonBL = new CommonBL();
var getResponseBody = commonBL.GetImposterRecordedRequests(pipelineConfigs.APIGatewayBaseUrl, _headers, "LessPayloadMockservice.json");
var isRecordRequest = (bool)getResponseBody["recordRequests"];
AssertTest.IsTrue(isRecordRequest, failMsg: "Record requests is not enabled in Less payload mockservice imposter", passMsg: "Record request is enabled in Less payload mockservice imposter");
var customHeaderRequest = getResponseBody["requests"].Where(x => x["headers"]["custom-header"] != null && x["headers"]["custom-header"].ToString() == "100").FirstOrDefault();
AssertTest.IsTrue(customHeaderRequest != null, failMsg: "custom-header is not found in upstream request headers", passMsg: "custom-header is available in upstream request headers");
}
[TestCategory(nameof(TestCategory.Nightly))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.OnPrem))]
[TestMethod]
public void PrefixReWriteTest()
{
//Make sure envoy config should have prefix:"/prefixrewritetest" and prefix_rewrite:"/mockserviceA"
Report.Step(@"API call with /prefixrewritetest/test url path", @"Url should be updated automatically to /mockserviceA/test and get the upstream response");
var customUniqueRequestHeaderValue = Guid.NewGuid().ToString();
_headers.Add(Constants.CustomUniqueRequestHeaderName, customUniqueRequestHeaderValue);
string prefixReWriteMockserviceUrl = $"{ pipelineConfigs.APIGatewayBaseUrl}/prefixrewritetest/test";
Logger.Info($"Mockservice Url: {prefixReWriteMockserviceUrl}");
var upstreamResponse = HttpClientUtility.ExecuteAndGetResponse(HttpMethod.Get, prefixReWriteMockserviceUrl, _headers, null);
CommonBL commonBL = new CommonBL();
_headers.Remove(Constants.CustomUniqueRequestHeaderName);
var upstreamRequestUrl = commonBL.GetUpstreamRecordedRequest(pipelineConfigs.APIGatewayBaseUrl, _headers, Constants.CustomUniqueRequestHeaderName, customUniqueRequestHeaderValue, "LessPayloadMockservice.json");
string reqUrl = upstreamRequestUrl["path"].ToString();
Logger.Info($"Upstream request url: { reqUrl}");
AssertTest.IsTrue(upstreamRequestUrl != null && reqUrl.EndsWith(appConfigs.LessPayloadMockservice, StringComparison.InvariantCultureIgnoreCase), failMsg: "custom-header is not found in upstream request headers", passMsg: "custom-header is available in upstream request headers");
AssertTest.IsTrue(upstreamResponse != null && upstreamResponse["status"].ToString().EqualsWithIgnoreCase("success"), failMsg: "No Success response received", passMsg: "Received Success response");
}
}
}

View File

@ -1,216 +0,0 @@
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using Driver.UI.Common;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Philips.EDI.Foundation.APIGateway.AutomationTest.BusinessLayer;
using Philips.EDI.Foundation.APIGateway.AutomationTest.Models;
using Philips.EDI.Foundation.APIGateway.AutomationTest.Tests.Common;
using Philips.EDI.Foundation.APIGateway.AutomationTest.Utilities;
using Reporters;
using Utilities;
namespace Philips.EDI.Foundation.APIGateway.AutomationTest.Tests.APITest
{
[TestClass]
public class ReverseProxyTests : BaseTest
{
private Cookies _cookie;
private readonly CommonSteps _commonSteps = new CommonSteps();
private readonly string _heavyPayloadMockServiceUrl = $"{pipelineConfigs.APIGatewayBaseUrl}/{ appConfigs.HeavyPayloadMockservice}";
private readonly string _serviceUnavailableMockServiceUrl = $"{pipelineConfigs.APIGatewayBaseUrl}/{ appConfigs.ServiceUnavailableMockservice}";
[TestInitialize]
public void BeforeTest()
{
Logger.Info("Before test");
_commonSteps.BrowseEndpointAndVerifyLogin(defaultEndpointUrl, pipelineConfigs.AuthUserName, pipelineConfigs.AuthPassword);
Report.Step(@"Get the cookie from browser", @"Should get the valid cookie");
AuthenticationBL authenticationBL = new AuthenticationBL(WebDriver);
_cookie = authenticationBL.GetCookie(pipelineConfigs.CookieName);
AssertTest.IsTrue(_cookie != null, failMsg: "Cookie is not available", passMsg: $"Cookie is available, Cookie value: {_cookie.CookieValue}");
}
[TestCategory(nameof(TestCategory.Nightly))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.OnPrem))]
[TestMethod]
public void PostCallWithLessPayloadTest()
{
Report.Step(@"POST API call to the less payload mockservice with the cookie", @"Should get the valid upstream response with Status: Success");
var (headers, requestBody) = GetRequestBody(defaultEndpointUrl);
var postResponseBody = HttpClientUtility.ExecuteAndGetResponse(HttpMethod.Post, defaultEndpointUrl, headers, requestBody);
AssertTest.IsTrue(postResponseBody != null && postResponseBody["status"].ToString().EqualsWithIgnoreCase("success"), failMsg: "No Success response received", passMsg: "Received Success response");
}
[TestCategory(nameof(TestCategory.GatedSanity))]
[TestCategory(nameof(TestCategory.Nightly))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.OnPrem))]
[TestMethod]
public void PostCallWithHeavyPayloadTest()
{
Report.Step(@"POST API call to the Heavy payload mockservice with the cookie", @"Should get the valid upstream response with Status: Success");
var (headers, requestBody) = GetRequestBody(_heavyPayloadMockServiceUrl);
var postResponseBody = HttpClientUtility.ExecuteAndGetResponse(HttpMethod.Post, _heavyPayloadMockServiceUrl, headers, requestBody);
AssertTest.IsTrue(postResponseBody != null && postResponseBody["status"].ToString().EqualsWithIgnoreCase("success"), failMsg: "No Success response received", passMsg: "Received Success response");
}
[TestCategory(nameof(TestCategory.Nightly))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.OnPrem))]
[TestMethod]
public void PostCallWhenUpstreamServiceDownTest()
{
Report.Step(@"POST API call to the Service unavailable mockservice with the cookie", @"Should get 503 Service Unavailable status");
var (headers, requestBody) = GetRequestBody(defaultEndpointUrl);
var postResponseBody = HttpClientUtility.ExecuteAsync(HttpMethod.Post, _serviceUnavailableMockServiceUrl, headers, requestBody);
AssertTest.IsTrue(postResponseBody.Result.StatusCode == HttpStatusCode.ServiceUnavailable, failMsg: "No StatusCode:503 Service Unavailable status received", passMsg: "Received StatusCode:503 Service Unavailable status");
}
[TestCategory(nameof(TestCategory.Nightly))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.OnPrem))]
[TestMethod]
public void GetCallWithLessPayloadTest()
{
Report.Step(@"GET API call to the less payload mockservice with the cookie", @"Should get the valid upstream response with Status: Success");
var headers = HttpClientUtility.CreateCookieHeader(pipelineConfigs.CookieName, _cookie.CookieValue);
Logger.Info($"GET endpoint Url: {defaultEndpointUrl}");
var getResponseBody = HttpClientUtility.ExecuteAndGetResponse(HttpMethod.Get, defaultEndpointUrl, headers, null);
AssertTest.IsTrue(getResponseBody != null && getResponseBody["status"].ToString().EqualsWithIgnoreCase("success"), failMsg: "No Success response received", passMsg: "Received Success response");
}
[TestCategory(nameof(TestCategory.GatedSanity))]
[TestCategory(nameof(TestCategory.Nightly))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.OnPrem))]
[TestMethod]
public void GetCallWithHeavyPayloadTest()
{
Report.Step(@"GET API call to the Heavy payload mockservice with the cookie", @"Should get the valid upstream response with Status: Success");
var headers = HttpClientUtility.CreateCookieHeader(pipelineConfigs.CookieName, _cookie.CookieValue);
Logger.Info($"GET endpoint Url: {_heavyPayloadMockServiceUrl}");
var getResponseBody = HttpClientUtility.ExecuteAndGetResponse(HttpMethod.Get, _heavyPayloadMockServiceUrl, headers, null);
AssertTest.IsTrue(getResponseBody != null && getResponseBody["status"].ToString().EqualsWithIgnoreCase("success"), failMsg: "No Success response received", passMsg: "Received Success response");
}
[TestCategory(nameof(TestCategory.Nightly))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.OnPrem))]
[TestMethod]
public void GetCallWhenUpstreamServiceDownTest()
{
Report.Step(@"GET API call to the Service unavailable mockservice with the cookie", @"Should get 503 Service Unavailable status");
var headers = HttpClientUtility.CreateCookieHeader(pipelineConfigs.CookieName, _cookie.CookieValue);
Logger.Info($"GET endpoint Url: {_serviceUnavailableMockServiceUrl}");
var getResponseBody = HttpClientUtility.ExecuteAsync(HttpMethod.Get, _serviceUnavailableMockServiceUrl, headers, null);
AssertTest.IsTrue(getResponseBody.Result.StatusCode == HttpStatusCode.ServiceUnavailable, failMsg: "No StatusCode:503 Service Unavailable status received", passMsg: "Received StatusCode:503 Service Unavailable status");
}
[TestCategory(nameof(TestCategory.GatedSanity))]
[TestCategory(nameof(TestCategory.Nightly))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.OnPrem))]
[TestMethod]
public void PutCallWithHeavyPayloadTest()
{
Report.Step(@"PUT API call to the Heavy payload mockservice with the cookie", @"Should get the valid upstream response with Status: Success");
var (headers, requestBody) = GetRequestBody(defaultEndpointUrl);
Logger.Info($"PUT call endpoint Url: {_heavyPayloadMockServiceUrl}");
var putResponseBody = HttpClientUtility.ExecuteAndGetResponse(HttpMethod.Put, _heavyPayloadMockServiceUrl, headers, requestBody);
AssertTest.IsTrue(putResponseBody != null && putResponseBody["status"].ToString().EqualsWithIgnoreCase("success"), failMsg: "No Success response received", passMsg: "Received Success response");
}
[TestCategory(nameof(TestCategory.Nightly))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.OnPrem))]
[TestMethod]
public void PutCallWhenUpstreamServiceDownTest()
{
Report.Step(@"PUT API call to the Service unavailable mockservice with the cookie", @"Should get 503 Service Unavailable status");
var (headers, requestBody) = GetRequestBody(defaultEndpointUrl);
Logger.Info($"PUT call endpoint Url: {_serviceUnavailableMockServiceUrl}");
var putResponseBody = HttpClientUtility.ExecuteAsync(HttpMethod.Put, _serviceUnavailableMockServiceUrl, headers, requestBody);
AssertTest.IsTrue(putResponseBody.Result.StatusCode == HttpStatusCode.ServiceUnavailable, failMsg: "No StatusCode:503 Service Unavailable status received", passMsg: "Received StatusCode:503 Service Unavailable status");
}
[TestCategory(nameof(TestCategory.GatedSanity))]
[TestCategory(nameof(TestCategory.Nightly))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.OnPrem))]
[TestMethod]
public void DeleteCallTest()
{
Report.Step(@"DELETE API call to the Heavy payload mockservice with cookie", @"Should get the valid upstream response with Status: Success");
var headers = HttpClientUtility.CreateCookieHeader(pipelineConfigs.CookieName, _cookie.CookieValue);
Logger.Info($"DELETE call endpoint Url: {_heavyPayloadMockServiceUrl}");
var responseBody = HttpClientUtility.ExecuteAndGetResponse(HttpMethod.Delete, _heavyPayloadMockServiceUrl, headers, null);
AssertTest.IsTrue(responseBody != null && responseBody["status"].ToString().EqualsWithIgnoreCase("success"), failMsg: "No Success response received", passMsg: "Received Success response");
}
[TestCategory(nameof(TestCategory.Nightly))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.OnPrem))]
[TestMethod]
public void DeleteCallWhenUpstreamServiceDownTest()
{
Report.Step(@"DELETE API call to the Service unavailable mockservice with cookie", @"Should get 503 Service Unavailable status");
var headers = HttpClientUtility.CreateCookieHeader(pipelineConfigs.CookieName, _cookie.CookieValue);
Logger.Info($"DELETE call endpoint Url: {_serviceUnavailableMockServiceUrl}");
var responseBody = HttpClientUtility.ExecuteAsync(HttpMethod.Delete, _serviceUnavailableMockServiceUrl, headers, null);
AssertTest.IsTrue(responseBody.Result.StatusCode == HttpStatusCode.ServiceUnavailable, failMsg: "No StatusCode:503 Service Unavailable status received", passMsg: "Received StatusCode:503 Service Unavailable status");
}
[TestCategory(nameof(TestCategory.GatedSanity))]
[TestCategory(nameof(TestCategory.Nightly))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.OnPrem))]
[TestMethod]
public void CDRUpstreamServiceAPICallTest()
{
Report.Step(@"GET API call to the CDR service with cookie", @"Should get the valid CDR service response");
var headers = HttpClientUtility.CreateCookieHeader(pipelineConfigs.CookieName, _cookie.CookieValue);
string cdrServiceUrl = $"{pipelineConfigs.APIGatewayBaseUrl}{appConfigs.CDRImagingStudyUrlPath.Replace("OrgId", tenantDetails[Constants.ValidTenantKey].IamOrganizationId)}";
Logger.Info($"CDR service Url: {cdrServiceUrl}");
var responseBody = HttpClientUtility.ExecuteAndGetResponse(HttpMethod.Get, cdrServiceUrl, headers, null);
AssertTest.IsTrue(responseBody != null && responseBody.ContainsKey("resourceType") && responseBody["resourceType"].ToString().EqualsWithIgnoreCase("Bundle"),
failMsg: "Failed to get the CDR service success response", passMsg: "Received the CDR service success response");
}
[TestCategory(nameof(TestCategory.Nightly))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.OnPrem))]
[TestMethod]
public void APICallsFromUIUpstreamInBrowserTest()
{
Report.Step(@"Browse the mountebank imposters endpoint url", @"Should get the mountebank imposters UI page in browser");
var impostersUrl = $"{pipelineConfigs.APIGatewayBaseUrl}/imposters";
Logger.Info($"Imposters page Url: {impostersUrl}");
ReverseProxyBL reverseProxyBL = new ReverseProxyBL(WebDriver);
AssertTest.IsTrue(reverseProxyBL.NavigateToImpostersPageAndGetIsMockServiceLinksDisplayed(impostersUrl), failMsg: "Imposters page is not displayed", passMsg: "Imposters page is displayed");
Report.Step(@"Click on less payload mockservice link and verify", @"Should get the less payload mockservice contents");
var isMockserviceADisplayed = reverseProxyBL.ClickOnImposterAndGetMockServiceContentIsDisplayed("ServiceA");
AssertTest.IsTrue(isMockserviceADisplayed, failMsg: "Less payload mockservice content is not displayed", passMsg: "Less payload mockservice content is displayed");
Report.Step(@"Click on Heavy payload mockservice link and verify", @"Should get the Heavy payload mockservice contents");
WebDriver.ClickOnBrowserBackButton();
var isMockserviceBDisplayed = reverseProxyBL.ClickOnImposterAndGetMockServiceContentIsDisplayed("ServiceB");
AssertTest.IsTrue(isMockserviceBDisplayed, failMsg: "Heavy payload mockservice content is not displayed", passMsg: "Heavy payload mockservice content is displayed");
}
private (Dictionary<string, string>, StringContent) GetRequestBody(string endpointUrl)
{
var headers = HttpClientUtility.CreateCookieHeader(pipelineConfigs.CookieName, _cookie.CookieValue);
Logger.Info($"GET API call endpoint Url: {endpointUrl}");
var getResponseBody = HttpClientUtility.ExecuteAndGetResponse(HttpMethod.Get, defaultEndpointUrl, headers, null);
var requestBody = HttpClientUtility.CreateHttpContent(getResponseBody.ToString());
Logger.Info($"Request body: {requestBody}");
return (headers, requestBody);
}
}
}

View File

@ -1,110 +0,0 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Philips.EDI.Foundation.APIGateway.AutomationTest.BusinessLayer;
using Philips.EDI.Foundation.APIGateway.AutomationTest.Models;
using Philips.EDI.Foundation.APIGateway.AutomationTest.Tests.Common;
using Philips.EDI.Foundation.APIGateway.AutomationTest.Utilities;
using Reporters;
using TimeZoneConverter;
using Utilities;
using Utilities.Wait;
namespace Philips.EDI.Foundation.APIGateway.AutomationTest.Tests.APITests
{
[TestClass]
public class IAMBrokerConfigurationTests : BaseTest
{
private readonly string _setKeyUrl = $"{pipelineConfigs.APIGatewayBaseUrl}{appConfigs.IamBrokerConfigAPIRelativePath.Replace("OrgId", tenantDetails[Constants.ValidTenantKey].IamOrganizationId)}";
private readonly VueSSOTokenBL _ssoTokenBL = new VueSSOTokenBL();
[TestCategory(nameof(TestCategory.OnPrem))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.IAMTokenExchangeBrokerPreCondition))]
[TestMethod]
public async Task SetSymmetricKeyWithValidAccessTokenTest()
{
Report.Step(@"Set symmetrickey with valid access token", @"Should get 204 NoContent response");
var userAccessTokenHeader = HttpClientUtility.CreateUserAccessTokenHeader(pipelineConfigs);
string url = $"{_setKeyUrl}{Constants.SymmetricKeyName}";
Logger.Info($"Symmetrickey set url: {url}");
var content = HttpClientUtility.CreateHttpContent($"\"{pipelineConfigs.OrgSymmetricKey}\"");
var response = await HttpClientUtility.ExecuteAsync(HttpMethod.Post, url, userAccessTokenHeader, content);
AssertTest.IsTrue(response != null && response.IsSuccessStatusCode && response.StatusCode == HttpStatusCode.NoContent, failMsg: $"Failed to set the symmetric key, StatusCode: {response.StatusCode}", passMsg: "Symmetrickey set successfully");
}
[TestCategory(nameof(TestCategory.OnPrem))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.IAMTokenExchangeBroker))]
[TestMethod]
public async Task SetSymmetricKeyWithInvalidAccessTokenTest()
{
Report.Step(@"Set symmetrickey with invalid access token", @"Should get 401 Unauthorized response");
var invalidAccessTokenHeader = new Dictionary<string, string>();
invalidAccessTokenHeader.Add("Authorization", $"Bearer {Guid.NewGuid()}");
string url = $"{_setKeyUrl}{Constants.SymmetricKeyName}";
Logger.Info($"Symmetrickey set url: {url}");
var content = HttpClientUtility.CreateHttpContent($"\"{pipelineConfigs.OrgSymmetricKey}\"");
var response = await HttpClientUtility.ExecuteAsync(HttpMethod.Post, _setKeyUrl, invalidAccessTokenHeader, content);
AssertTest.IsTrue(response.StatusCode == HttpStatusCode.Unauthorized, failMsg: $"Not received HttpStatusCode 401 Unauthorized, Actual: {response.StatusCode}", passMsg: "Received HttpStatusCode.Unauthorized");
}
[TestCategory(nameof(TestCategory.OnPrem))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.IAMTokenExchangeBroker))]
[TestMethod]
public async Task SetTimeZoneWithTokyoStandardTimeTest()
{
try
{
await SetTimeZoneAndValidate(Constants.TokyoTimeZone);
var response = await APICallWithSSOTokenAndGetResponse(Constants.TokyoTimeZone, defaultEndpointUrl);
AssertTest.IsTrue(response != null && response.IsSuccessStatusCode, failMsg: $"TimeZone:{Constants.TokyoTimeZone}, Not received HttpStatusCode 200, Actual: {response.StatusCode}", passMsg: "Received HttpStatusCode 200");
response = await APICallWithSSOTokenAndGetResponse(Constants.UTCTimeZone, defaultEndpointUrl);
AssertTest.IsTrue(response != null && response.StatusCode == HttpStatusCode.Unauthorized, failMsg: $"TimeZone:{Constants.UTCTimeZone}, Not received HttpStatusCode 401 Unauthorized, Actual: {response.StatusCode}", passMsg: "Received HttpStatusCode.Unauthorized");
}
catch (Exception ex)
{
Logger.InfoFailedWithException(ex);
}
finally
{
await SetTimeZoneAndValidate(Constants.UTCTimeZone);
var response = await APICallWithSSOTokenAndGetResponse(Constants.UTCTimeZone, defaultEndpointUrl);
AssertTest.IsTrue(response != null && response.IsSuccessStatusCode, failMsg: $"TimeZone:{Constants.UTCTimeZone}, Not received HttpStatusCode 200, Actual: {response.StatusCode}", passMsg: "Received HttpStatusCode 200");
}
}
#region private methods
private async Task SetTimeZoneAndValidate(string timeZoneName)
{
Report.Step($"Set {timeZoneName} timezone", @"Should get 204 NoContent response");
var userAccessTokenHeader = HttpClientUtility.CreateUserAccessTokenHeader(pipelineConfigs);
string url = $"{_setKeyUrl}{Constants.TimeZoneKeyName}";
timeZoneName = $"\"{timeZoneName}\"";
Logger.Info($"Set Timezone url: {url}");
var content = HttpClientUtility.CreateHttpContent(timeZoneName);
var response = await HttpClientUtility.ExecuteAsync(HttpMethod.Post, url, userAccessTokenHeader, content);
AssertTest.IsTrue(response.IsSuccessStatusCode && response.StatusCode == HttpStatusCode.NoContent, failMsg: $"Failed to set the time zone- {timeZoneName}, StatusCode: {response.StatusCode}", passMsg: $"TimeZone was set successfully, StatusCode: {response.StatusCode}");
}
private Task<HttpResponseMessage> APICallWithSSOTokenAndGetResponse(string timeZoneName, string url)
{
Report.Step($"API call with SSO token generated with {timeZoneName} timezone", @"Should get the upstream response");
var tzi = TZConvert.GetTimeZoneInfo(timeZoneName);
string ssoToken = _ssoTokenBL.GenerateSsoToken("user", TimeZoneInfo.ConvertTime(DateTimeOffset.UtcNow, tzi).DateTime.ToString(Constants.TimeStampFormat), pipelineConfigs.OrgSymmetricKey);
Sleep.Seconds(appConfigs.MountibankTimeoutinSeconds);
var headers = new Dictionary<string, string>();
headers.TryAdd("EDISP-vuesso", ssoToken);
headers.TryAdd("edisp-vuesso-orgid", tenantDetails[Constants.ValidTenantKey].IamOrganizationId);
return HttpClientUtility.ExecuteAsync(HttpMethod.Get, url, headers, null);
}
#endregion
}
}

View File

@ -1,62 +0,0 @@
using System.Collections.Generic;
using System.Net.Http;
using Newtonsoft.Json;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Philips.EDI.Foundation.APIGateway.AutomationTest.Models;
using Philips.EDI.Foundation.APIGateway.AutomationTest.Tests.Common;
using Philips.EDI.Foundation.APIGateway.AutomationTest.Utilities;
using Reporters;
using Utilities;
using IdentityModel.Jwk;
namespace Philips.EDI.Foundation.APIGateway.AutomationTest.Tests.APITests
{
[TestClass]
public class IDTokenValidatorTests : BaseTest
{
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.GatedSanity))]
[TestCategory(nameof(TestCategory.IDTokenValidator))]
[TestCategory(nameof(TestCategory.UpgradeSanity))]
[TestCategory(nameof(TestCategory.IntegratedSanity))]
[TestMethod]
public void GetOpenIdConfigurationAndVerifyJWKSDataTest()
{
var openIdConfigOrgs = JsonConvert.DeserializeObject<List<OpenIdConfigOrganizationCertificateMapping>>(pipelineConfigs.OpenIdConfigOrganizationCertificateMapping);
Report.Step(@"Get Jwks url from OpenId Configuration get call for multitenant ", @"Should get the respective tenant Jwks url");
foreach (var org in openIdConfigOrgs)
{
string openIdConfigUrl = $"{pipelineConfigs.OpenIdConfigurationBaseUrl}{appConfigs.OpenIdConfigurationUrlPath.Replace("OrgId", org.OrganizationId)}";
Logger.Info($"OpenId Configuration url: {openIdConfigUrl}");
var openIdConfigResponse = HttpClientUtility.ExecuteAndGetResponse(HttpMethod.Get, openIdConfigUrl, new Dictionary<string, string>(), null);
string jwksUrl = openIdConfigResponse["jwks_uri"]?.ToString();
Logger.Info($"Jwks Url: {jwksUrl}");
AssertTest.IsTrue(!string.IsNullOrWhiteSpace(jwksUrl) && jwksUrl.Contains($"/{org.OrganizationId}/"), failMsg: $"Failed to get Jwks url for the orgId: {org}", passMsg: "Jwks url is fetched successfully");
Report.Step(@"Get Jwks keys from the get call of jwks url", @"All the Jwks keys should not be null");
var jwksResponse = HttpClientUtility.ExecuteAndGetResponse(HttpMethod.Get, jwksUrl, new Dictionary<string, string>(), null);
var jwksData = JsonConvert.DeserializeObject<JsonWebKey>(jwksResponse["keys"]?.First.ToString());
string expectedCert = RemoveCertificateBoundaryAndLineBreaks(org.Certificate);
AssertTest.IsTrue(jwksData.X5c != null && jwksData.X5c[0].Equals(expectedCert), failMsg: $"Property 'x5c' value is null ", passMsg: $"Property 'x5c(certificate)' value is matching with expected value");
AssertTest.IsTrue(jwksData.Kid != null, failMsg: $"Property 'Kid' value is null ", passMsg: $"Property 'Kid' is not null ");
AssertTest.IsTrue(jwksData.Kty != null, failMsg: $"Property 'Kty' value is null ", passMsg: $"Property 'Kty' is not null ");
AssertTest.IsTrue(jwksData.Alg != null, failMsg: $"Property 'alg' value is null ", passMsg: $"Property 'alg' is not null ");
AssertTest.IsTrue(jwksData.Use != null, failMsg: $"Property 'Use' value is null ", passMsg: $"Property 'Use' is not null ");
AssertTest.IsTrue(jwksData.N != null, failMsg: $"Property 'N' value is null ", passMsg: $"Property 'N' is not null ");
AssertTest.IsTrue(jwksData.E != null, failMsg: $"Property 'E' value is null ", passMsg: $"Property 'E' is not null ");
}
}
#region private methods
private string RemoveCertificateBoundaryAndLineBreaks(string certData)
{
return certData.Replace("-----BEGIN CERTIFICATE-----", string.Empty)
.Replace("-----END CERTIFICATE-----", string.Empty)
.Replace("\r\n", "\n").Replace("\r", "\n").Replace("\n", string.Empty);
}
#endregion
}
}

View File

@ -1,220 +0,0 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Philips.EDI.Foundation.APIGateway.AutomationTest.BusinessLayer;
using Philips.EDI.Foundation.APIGateway.AutomationTest.Tests.Common;
using Philips.EDI.Foundation.APIGateway.AutomationTest.Models;
using System;
using System.Collections.Generic;
using Philips.EDI.Foundation.APIGateway.AutomationTest.Utilities;
using System.Net.Http;
using Reporters;
using System.Linq;
using System.Threading.Tasks;
using Utilities.Wait;
namespace Philips.EDI.Foundation.APIGateway.AutomationTest.Tests.APITests.SSOTokenAuthenticatorTests
{
[TestClass]
public class SSOTokenAuthenticatorTests : BaseTest
{
private readonly VueSSOTokenBL _ssoTokenBL = new VueSSOTokenBL();
private readonly HSPIAMBusinessLayer _iamBL = new HSPIAMBusinessLayer();
private string ssoToken;
private string userName;
string cdrServiceUrl = $"{pipelineConfigs.APIGatewayBaseUrl}{appConfigs.CDRImagingStudyUrlPath.Replace("OrgId", tenantDetails[Constants.ValidTenantKey].IamOrganizationId)}";
string getStudyDetailsUrl = $"{pipelineConfigs.CDRBaseUrl}{appConfigs.CDRImagingStudyUrlPath.Replace("OrgId", tenantDetails[Constants.ValidTenantKey].IamOrganizationId)}?_count=1";
[TestCategory(nameof(TestCategory.SSOToken))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.OnPrem))]
[TestMethod]
public void UserwithPermissionsTest()
{
Report.Step(@"CDR Call with SSO token header of user having required permission", @"Should get the valid upstream response");
var response = GetUpstreamResponseWithSSOToken(pipelineConfigs.SSOTokenUserName, pipelineConfigs.OrgSymmetricKey);
AssertTest.IsTrue(response.ToString().Contains("StatusCode: 200"), failMsg: $"StatusCode was not 200, Resopnse Message: {response}", passMsg: "Received success response with statuscode as 200");
}
[TestCategory(nameof(TestCategory.SSOToken))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.OnPrem))]
[TestMethod]
public void CreateUserwithoutPermissionsTest()
{
try
{
Report.Step(@"CDR Call with SSO token header of a new user not having required permission", @"Should get 401 unauthorized upstream response");
Random rand = new Random();
userName = "autoTest"+ rand.Next(99, 9999);
var response = GetUpstreamResponseWithSSOToken(userName, pipelineConfigs.OrgSymmetricKey);
AssertTest.IsTrue(response.ToString().Contains("StatusCode: 401"), failMsg: "CDR call did not returned Unauthorized access",
passMsg: "CDR call returned Status code of 401 Unauthorized access as expected");
}
catch (Exception e)
{
Report.ReportError("Exception",e.ToString());
}
finally
{
//Deleting the created automation user
var userAccessTokenHeader = CreateUserAccessTokenHeader();
_ = _iamBL.DeleteUser(pipelineConfigs.IAMGetUserUrl, pipelineConfigs.IDMClientBaseUrl, userName+ "_rubyhealthiamte@vue.com", userAccessTokenHeader);
}
}
[TestCategory(nameof(TestCategory.SSOToken))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.OnPrem))]
[TestMethod]
public void UserwithWrongSSOTokenHeaderTest()
{
Report.Step(@"CDR Call with with wrong SSO token header of a user", @"Should get invalid sso token upstream response");
var headers = new Dictionary<string, string>();
headers.TryAdd("EDISP-vuesso", "InvalidSSOToken");
headers.TryAdd("edisp-vuesso-orgid", tenantDetails[Constants.ValidTenantKey].IamOrganizationId);
var response = HttpClientUtility.ExecuteAndGetResponse(HttpMethod.Get, cdrServiceUrl, headers, null);
AssertTest.IsTrue(response["Detail"].ToString().EqualsWithIgnoreCase("Please provide valid sso token and symmetric key"),
failMsg: "CDR call did not returned 'Please provide valid sso token and symmetric key' error response",
passMsg: "CDR call returned error message 'Please provide valid sso token and symmetric key' as expected");
}
[TestCategory(nameof(TestCategory.SSOToken))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.OnPrem))]
[TestMethod]
public void UserwithInvalidOrgIdHeaderTest()
{
Report.Step(@"CDR Call with with wrong orgId header", @"Should get the given key is not present in the dictionary upstream response");
var headers = new Dictionary<string, string>();
ssoToken = _ssoTokenBL.GenerateSsoToken(pipelineConfigs.SSOTokenUserName, DateTime.UtcNow.AddMinutes(0).ToString(Constants.TimeStampFormat), pipelineConfigs.OrgSymmetricKey);
headers.TryAdd("EDISP-vuesso", ssoToken);
headers.TryAdd("edisp-vuesso-orgid", string.Empty);
var response = HttpClientUtility.ExecuteAndGetResponse(HttpMethod.Get, cdrServiceUrl, headers, null);
var message = "orgId is empty, set it in edisp-vuesso-orgid header";
AssertTest.IsTrue(response["Detail"].ToString().EqualsWithIgnoreCase(message),
failMsg: $"CDR call did not returned '{message}' error response",
passMsg: $"CDR call returned error message '{message}' as expected");
}
[TestCategory(nameof(TestCategory.SSOToken))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.OnPrem))]
[TestMethod]
public void UserwithExpiredSSOTokenTest()
{
Report.Step(@"CDR Call with with Expired SSO token header of a user with all required permission", @"Should get invalid sso token session timed out upstream response");
ssoToken = _ssoTokenBL.GenerateSsoToken(pipelineConfigs.SSOTokenUserName, DateTime.UtcNow.AddMinutes(-31).ToString(Constants.TimeStampFormat), pipelineConfigs.OrgSymmetricKey);
var headers = new Dictionary<string, string>();
headers.TryAdd("EDISP-vuesso", ssoToken);
headers.TryAdd("edisp-vuesso-orgid", tenantDetails[Constants.ValidTenantKey].IamOrganizationId);
var response = HttpClientUtility.ExecuteAndGetResponse(HttpMethod.Get, cdrServiceUrl, headers, null);
AssertTest.IsTrue(response["Detail"].ToString().EqualsWithIgnoreCase("SSO token session timed out"),
failMsg: "CDR call did not returned 'SSO token session timed out' error response",
passMsg: "CDR call returned error message 'SSO token session timed out' as expected");
}
[TestCategory(nameof(TestCategory.SSOToken))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.OnPrem))]
[TestMethod]
public async Task AccessTokenValueisTakenFromCacheTest()
{
Report.Step(@"Verify that new session with same user uses same cached accesstoken",
@"same cached access token should be used");
List<string> accessTokenValues = new List<string>();
for (int i = 0; i < 2; i++)
{
var headers = new Dictionary<string, string>();
string customUniqueRequestHeaderValue = Guid.NewGuid().ToString();
headers.Add(Constants.CustomUniqueRequestHeaderName, customUniqueRequestHeaderValue);
ssoToken = _ssoTokenBL.GenerateSsoToken(pipelineConfigs.SSOTokenUserName, DateTime.UtcNow.ToString(Constants.TimeStampFormat), pipelineConfigs.OrgSymmetricKey);
headers.TryAdd("EDISP-vuesso", ssoToken);
headers.TryAdd("edisp-vuesso-orgid", tenantDetails[Constants.ValidTenantKey].IamOrganizationId);
Sleep.Seconds(appConfigs.MountibankTimeoutinSeconds);
_ = await HttpClientUtility.ExecuteAsync(HttpMethod.Get, defaultEndpointUrl, headers, null);
CommonBL commonBL = new CommonBL();
var testHeaderRequest = commonBL.GetUpstreamRecordedRequest(pipelineConfigs.APIGatewayBaseUrl, headers, Constants.CustomUniqueRequestHeaderName, customUniqueRequestHeaderValue, "LessPayloadMockservice.json");
accessTokenValues.Add(testHeaderRequest["headers"]["authorization"].ToString());
}
AssertTest.IsTrue(accessTokenValues.First().Equals(accessTokenValues.Last()), failMsg: "New session with same user is not using same cached accesstoken",
passMsg: "New session with same user is using cached accesstoken");
}
[TestCategory(nameof(TestCategory.SSOToken))]
[TestCategory(nameof(TestCategory.OnPrem))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestMethod]
public void InvalidSymmetricKeyTest()
{
Report.Step(@"CDR Call with SSO token header of Invalid Symmetric Key", @"Should get 401 unauthorized upstream response");
var response = GetUpstreamResponseWithSSOToken(pipelineConfigs.SSOTokenUserName, "rpJupVvvHiX5kgrPllV8gWsurbzSu9D99kUwamFdL9I=");
AssertTest.IsTrue(response.ToString().Contains("StatusCode: 401"), failMsg: "CDR call did not returned Unauthorized access",
passMsg: "CDR call returned Status code of 401 Unauthorized access as expected");
}
/// <summary>
/// Method to get the Upstream response with SSO token
/// </summary>
/// <param name="userName">UserName to generate the SSO Token</param>
/// <param name="addMin">addMinutes value</param>
/// /// <param name="symmetricKey">SymmetricKey of org value</param>
/// <returns>HttpResponseMessage</returns>
private HttpResponseMessage GetUpstreamResponseWithSSOToken(String userName,string symmetricKey, int addMin = 0)
{
try
{
Report.Step(@"CDR Call with SSO token header of user having required permission", @"Should get the valid upstream response");
ssoToken = _ssoTokenBL.GenerateSsoToken(userName, DateTime.UtcNow.AddMinutes(addMin).ToString(Constants.TimeStampFormat), symmetricKey);
var headers = new Dictionary<string, string>();
Sleep.Seconds(appConfigs.MountibankTimeoutinSeconds);
headers.TryAdd("edisp-vuesso", ssoToken);
headers.TryAdd("edisp-vuesso-orgid", tenantDetails[Constants.ValidTenantKey].IamOrganizationId);
return HttpClientUtility.ExecuteAsync(HttpMethod.Get, cdrServiceUrl + "/" + GetStudyUidDetails(), headers, null).Result;
}
catch (Exception e)
{
Report.ReportError("Exception", e.ToString());
throw;
}
}
/// <summary>
/// Method to get the single studyuid details based on organization
/// </summary>
/// <returns>string of study id</returns>
private string GetStudyUidDetails()
{
Report.Step(@"Get Study details for the Org", @"Should get the study details");
var headers = CreateUserAccessTokenHeader();
headers.TryAdd("api-version", "1");
var responseBody = HttpClientUtility.ExecuteAndGetResponse(HttpMethod.Get, getStudyDetailsUrl, headers, null);
var studyDetails = responseBody["entry"]?.Where(x => x["resource"]["id"] != null).Select(x => x["resource"]?["id"]?.ToString()).ToList()[0];
if (string.IsNullOrEmpty((studyDetails)))
{
AssertTest.IsTrue(false, "Fetched Study details were empty", "", false);
}
else
{
AssertTest.IsTrue(true, "", "Study details were fetched", false);
}
return studyDetails;
}
/// <summary>
/// Method to created Access Token header
/// </summary>
/// <returns>Dictionary<Key, value></returns>
private Dictionary<string, string> CreateUserAccessTokenHeader()
{
var userAccessTokenHeader = HttpClientUtility.CreateUserAccessTokenHeader(pipelineConfigs);
AssertTest.IsTrue(userAccessTokenHeader != null, failMsg: "User Access Token header is null", passMsg: $"User Access Token header is not null");
return userAccessTokenHeader;
}
}
}

View File

@ -1,149 +0,0 @@
using System;
using System.IO;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Philips.EDI.Foundation.APIGateway.AutomationTest.Models;
using Philips.EDI.Foundation.APIGateway.AutomationTest.Utilities;
using Reporters;
using Utilities;
using Utilities.Enums;
using Driver.UI.Interfaces;
using Driver.UI.Selenium;
using Utilities.Wait;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
namespace Philips.EDI.Foundation.APIGateway.AutomationTest.Tests.Common
{
[TestClass]
public abstract class BaseTest
{
public static IWebDriverUi WebDriver
{
get => _WebDriver;
}
public static ReportManager Report
{
get => _report;
}
public TestContext TestContext
{
get => _testContext;
set => _testContext = value;
}
public static readonly AppConfiguration appConfigs = Settings.GetConfiguration<AppConfiguration>(typeof(AppConfiguration).Name);
public static readonly PipelineConfiguration pipelineConfigs = Settings.GetConfiguration<PipelineConfiguration>(typeof(PipelineConfiguration).Name);
public static readonly Dictionary<string, TenantMapping> tenantDetails = JsonConvert.DeserializeObject<Dictionary<string, TenantMapping>>(pipelineConfigs.TenantDetails);
public readonly string defaultEndpointUrl = $"{pipelineConfigs.APIGatewayBaseUrl}{ appConfigs.LessPayloadMockservice}";
private ReporterBase _ReporterBase;
private static IWebDriverUi _WebDriver;
private static ReportManager _report;
private TestContext _testContext;
private readonly string _outputFolder = Path.Combine(appConfigs.RootFolder, "Logs");
private readonly ReporterTestInfo _testInfo = new ReporterTestInfo();
[TestInitialize]
public void Before()
{
Logger.Info("######### Start Test ######### Test Name: " + _testContext.TestName + "\r\n");
_ReporterBase = new ReporterBase(_outputFolder, appConfigs.ReporterList, appConfigs.RootFolder,
appConfigs.RootEvidencePath, appConfigs.DifidoFolderLocation, appConfigs.ProductName);
_report = _ReporterBase.GetReportMngInstance(_testContext.TestName, _testContext.FullyQualifiedTestClassName, _testInfo);
AssertTest.ConfigureServices(TestProjectType.MsTest);
AssertTest.InitAssertService();
ProcessUtilities.KillChromeDriver();
}
[TestCleanup]
public void After()
{
if (!TestContext.CurrentTestOutcome.Equals(UnitTestOutcome.Passed) &&
Report.CurrentStepStatus == Reporters.BaseReport.Enums.Enum.StepStatus.Passed)
Report.ReportError("The test has failed by throw an exception (not by any assert validation)");
_ReporterBase.CloseReports(_testInfo);
if (Report != null && WebDriver != null)
{
_ = WebDriver.Quit();
}
ProcessUtilities.KillChromeDriver();
Logger.Info("######### End Test ######### Test Name: " + _testContext.TestName + "\r\n");
}
protected bool LoginToEndpoint(string endpointUrl, string userName, string password)
{
Logger.InfoStartMethod();
try
{
Logger.Info($"Endpoint url: {endpointUrl}");
_WebDriver = new SeleniumDriver(Driver.Enums.BrowserType.Chrome, endpointUrl, null);
object userNameElement = null;
WaitUtils.WaitUntil(() =>
{
userNameElement = WebDriver.FindElementById("idToken1");
return WebDriver.IsExist(userNameElement);
}, 60);
_ = WebDriver.TypeText(userNameElement, userName);
_ = WebDriver.TypeText(WebDriver.FindElementById("idToken2"), password);
_ = WebDriver.Click(WebDriver.FindElementById("loginButton_0"));
var saveConsentCheckBox = WebDriver.FindElementById("saveConsent");
if (WebDriver.IsExist(saveConsentCheckBox))
{
Logger.Info($"Save Consent exists");
_ = WebDriver.Click(saveConsentCheckBox);
_ = WebDriver.Click(WebDriver.FindElementByXPath("//button[@value='allow']"));
}
var bodyElement = WebDriver.FindElementByXPath("//body/pre | //a[text()='home']");
return WebDriver.IsExist(bodyElement);
}
catch (Exception ex)
{
Logger.InfoFailedWithException(ex);
throw;
}
finally
{
WebDriver.TakeScreenshot();
}
}
protected JObject GetResponseFromUI()
{
try
{
var bodyElement = WebDriver.FindElementByXPath("//body/pre");
if (WebDriver.IsExist(bodyElement))
{
string responseJson = WebDriver.GetText(bodyElement);
return JObject.Parse(responseJson);
}
}
catch (Exception ex)
{
Logger.InfoFailedWithException(ex);
throw;
}
return null;
}
protected bool IsLoginPageDisplayed()
{
var userNameElement = WebDriver.FindElementById("idToken1");
var passwordElement = WebDriver.FindElementById("idToken2");
return WebDriver.IsExist(userNameElement) && WebDriver.IsExist(passwordElement);
}
}
}

View File

@ -1,73 +0,0 @@
using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
using Philips.EDI.Foundation.APIGateway.AutomationTest.Utilities;
using Reporters;
using Utilities.Wait;
namespace Philips.EDI.Foundation.APIGateway.AutomationTest.Tests.Common
{
public class CommonSteps : BaseTest
{
public void BrowseEndpointAndVerifyLogin(string endpoint, string userName, string password)
{
Report.Step(@"Browse the endpoint url and login", @"Should successfully login and get the upstream response");
var isLoginSuccessful = LoginToEndpoint(endpoint, userName, password);
AssertTest.IsTrue(isLoginSuccessful, failMsg: "Login Unsuccessful", passMsg: "Login Successful");
var responseBody = GetResponseFromUI();
AssertTest.IsTrue(responseBody != null && responseBody["status"].ToString().EqualsWithIgnoreCase("success"), failMsg: "No Success response", passMsg: "Received success response");
}
public bool LogoutWithPOST(string endpointUrl, string userName, string password)
{
try
{
IWebDriver _localWebDriver = new ChromeDriver();
_localWebDriver.Url = defaultEndpointUrl;
_localWebDriver.Navigate();
WebDriverWait wait = new WebDriverWait(_localWebDriver,TimeSpan.FromSeconds(20));
wait.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(By.Id("idToken1")));
IWebElement userNameElement = null;
WaitUtils.WaitUntil(() =>
{
userNameElement = _localWebDriver.FindElement(By.Id("idToken1"));
return userNameElement.Displayed;
}, 60);
userNameElement.SendKeys(userName);
_localWebDriver.FindElement(By.Id("idToken2")).SendKeys(password); ;
_localWebDriver.FindElement(By.Id("loginButton_0")).Click();
wait.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(By.XPath("//body/pre | //a[text()='home']")));
IWebElement bodyElement = _localWebDriver.FindElement(By.XPath("//body/pre | //a[text()='home']"));
if(bodyElement.Displayed)
{
IJavaScriptExecutor js = (IJavaScriptExecutor)_localWebDriver;
string title = (string)js.ExecuteScript("navigator.sendBeacon('/logout');");
}
_localWebDriver.Navigate().Refresh();
wait.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(By.Id("idToken1")));
userNameElement = _localWebDriver.FindElement(By.Id("idToken1"));
bool isLoginPage = userNameElement.Enabled;
_localWebDriver.Quit();
return isLoginPage;
}
catch (Exception ex)
{
Report.ReportError(ex.ToString(), "LogoutWithPOST");
throw;
}
}
}
}

View File

@ -1,285 +0,0 @@
{
"protocol": "http",
"port": 4546,
"name": "ServiceB",
"recordRequests": false,
"defaultResponse": {
"statusCode": 404
},
"stubs": [
{
"predicates": [
{
"endsWith": {
"path": "/test"
}
},
{
"equals": {
"method": "POST"
}
},
{
"or": [
{
"contains": {
"headers": {
"cookie": "edi_session"
}
}
},
{
"startsWith": {
"headers": {
"authorization": "bearer"
}
}
}
]
},
{
"matches": {
"body": ".*"
}
}
],
"responses": [
{
"is": {
"statusCode": 201,
"body": {
"status": "Success",
"message": "POST request received for sample payload"
}
}
}
]
},
{
"predicates": [
{
"endsWith": {
"path": "/test"
}
},
{
"equals": {
"method": "GET"
}
},
{
"or": [
{
"contains": {
"headers": {
"cookie": "edi_session"
}
}
},
{
"startsWith": {
"headers": {
"authorization": "bearer"
}
}
}
]
}
],
"responses": [
{
"is": {
"statusCode": 200,
"body": {
"status": "Success",
"SamplePayload": {
"PickupTruckA": {
"options": [
"manual transmission",
"sunroof",
"premium stereo"
],
"manufactureDate": "2019-01-15",
"current_location": {
"lat": 37.773972,
"lon": -122.431297
},
"fullLength": 230.25,
"used": true,
"price": 35000,
"previousOwner": {
"firstName": "John",
"lastName": "Smith"
}
},
"PickupTruckB": {
"options": [
"automatic transmission",
"keyless entry"
],
"manufactureDate": "2018-06-12",
"current_location": {
"lat": 39.742043,
"lon": -104.991531
},
"fullLength": 215.75,
"used": true,
"price": 29500,
"previousOwner": {
"firstName": "Jane",
"lastName": "Jones"
}
},
"PickupTruckC": {
"options": [
"automatic transmission",
"keyless entry"
],
"manufactureDate": "2018-06-12",
"current_location": {
"lat": 39.742043,
"lon": -104.991531
},
"fullLength": 215.75,
"used": true,
"price": 29500,
"previousOwner": {
"firstName": "Jane",
"lastName": "Jones"
}
},
"PickupTruckD": {
"options": [
"automatic transmission",
"keyless entry"
],
"manufactureDate": "2018-06-12",
"current_location": {
"lat": 39.742043,
"lon": -104.991531
},
"fullLength": 215.75,
"used": true,
"price": 29500,
"previousOwner": {
"firstName": "Jane",
"lastName": "Jones"
}
},
"PickupTruckE": {
"options": [
"automatic transmission",
"keyless entry"
],
"manufactureDate": "2018-06-12",
"current_location": {
"lat": 39.742043,
"lon": -104.991531
},
"fullLength": 215.75,
"used": true,
"price": 29500,
"previousOwner": {
"firstName": "Jane",
"lastName": "Jones"
}
}
}
}
}
}
]
},
{
"predicates": [
{
"endsWith": {
"path": "/test"
}
},
{
"equals": {
"method": "PUT"
}
},
{
"or": [
{
"contains": {
"headers": {
"cookie": "edi_session"
}
}
},
{
"startsWith": {
"headers": {
"authorization": "bearer"
}
}
}
]
},
{
"matches": {
"body": ".*"
}
}
],
"responses": [
{
"is": {
"statusCode": 201,
"body": {
"status": "Success",
"message": "PUT request received for sample payload"
}
}
}
]
},
{
"predicates": [
{
"endsWith": {
"path": "/test"
}
},
{
"equals": {
"method": "DELETE"
}
},
{
"or": [
{
"contains": {
"headers": {
"cookie": "edi_session"
}
}
},
{
"startsWith": {
"headers": {
"authorization": "bearer"
}
}
}
]
}
],
"responses": [
{
"is": {
"statusCode": 201,
"body": {
"status": "Success",
"message": "DELETE request received"
}
}
}
]
}
]
}

View File

@ -1,284 +0,0 @@
{
"protocol": "http",
"port": 4545,
"name": "ServiceA",
"numberOfRequests": 0,
"recordRequests": true,
"requests": [
],
"defaultResponse": {
"statusCode": 404
},
"stubs": [
{
"predicates": [
{
"endsWith": {
"path": "/test"
}
},
{
"equals": {
"method": "POST"
}
},
{
"or": [
{
"contains": {
"headers": {
"cookie": "edi_session"
}
}
},
{
"startsWith": {
"headers": {
"authorization": "bearer"
}
}
}
]
},
{
"matches": {
"body": ".*"
}
}
],
"responses": [
{
"is": {
"statusCode": 201,
"body": {
"status": "Success",
"message": "POST request received for sample payload"
}
}
}
]
},
{
"predicates": [
{
"endsWith": {
"path": "/test"
}
},
{
"equals": {
"method": "GET"
}
},
{
"or": [
{
"contains": {
"headers": {
"cookie": "edi_session"
}
}
},
{
"startsWith": {
"headers": {
"authorization": "bearer"
}
}
}
]
}
],
"responses": [
{
"is": {
"statusCode": 200,
"body": {
"status": "Success"
}
}
}
]
},
{
"predicates": [
{
"contains": {
"path": "/multitenancy"
}
},
{
"equals": {
"method": "GET"
}
},
{
"or": [
{
"contains": {
"headers": {
"cookie": "edi_session"
}
}
},
{
"startsWith": {
"headers": {
"authorization": "bearer"
}
}
}
]
}
],
"responses": [
{
"is": {
"statusCode": 200,
"body": {
"status": "Success"
}
}
}
]
},
{
"predicates": [
{
"endsWith": {
"path": "/test"
}
},
{
"equals": {
"method": "PUT"
}
},
{
"or": [
{
"contains": {
"headers": {
"cookie": "edi_session"
}
}
},
{
"startsWith": {
"headers": {
"authorization": "bearer"
}
}
}
]
},
{
"matches": {
"body": ".*"
}
}
],
"responses": [
{
"is": {
"statusCode": 201,
"body": {
"status": "Success",
"message": "PUT request received for sample payload"
}
}
}
]
},
{
"predicates": [
{
"endsWith": {
"path": "/test"
}
},
{
"equals": {
"method": "DELETE"
}
},
{
"or": [
{
"contains": {
"headers": {
"cookie": "edi_session"
}
}
},
{
"startsWith": {
"headers": {
"authorization": "bearer"
}
}
}
]
}
],
"responses": [
{
"is": {
"statusCode": 204,
"body": {
"status": "Success",
"message": "DELETE request received"
}
}
}
]
},
{
"predicates": [
{
"endsWith": {
"path": "/test/checkpermission"
}
},
{
"equals": {
"method": "GET"
}
},
{
"or": [
{
"contains": {
"headers": {
"cookie": "edi_session"
}
}
},
{
"startsWith": {
"headers": {
"authorization": "bearer"
}
}
}
]
},
{
"inject": "function (config) {\r\n\r\n var base64DecodedIntrospectValue = Buffer.from(config.request.headers[\"edisp-introspect-value\"], \"base64\").toString();\r\n\tvar orgList = JSON.parse(base64DecodedIntrospectValue )[\"organizations\"][\"organizationList\"];\r\n\r\n\tfor (let i in orgList) { \r\n\t\tif(orgList[i][\"organizationId\"] === config.request.headers[\"edisp-org-id\"])\r\n\t\t{\r\n\t\t\treturn !orgList[i][\"permissions\"].includes(config.request.headers[\"permission-name\"]); \r\n\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n}"
}
],
"responses": [
{
"is": {
"statusCode": 403,
"body": {
"status": "Forbidden",
"message": "Access Forbidden"
}
}
}
]
}
]
}

View File

@ -1,54 +0,0 @@
using System.IO;
using System.Net;
using System.Net.Http;
using System.Reflection;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json.Linq;
using Philips.EDI.Foundation.APIGateway.AutomationTest.BusinessLayer;
using Philips.EDI.Foundation.APIGateway.AutomationTest.Models;
using Philips.EDI.Foundation.APIGateway.AutomationTest.Tests.Common;
using Philips.EDI.Foundation.APIGateway.AutomationTest.Utilities;
using Reporters;
using Utilities;
namespace Philips.EDI.Foundation.APIGateway.AutomationTest.Tests.APITest
{
[TestClass]
public class PostDeploymentTests : BaseTest
{
[TestCategory(nameof(TestCategory.PostDeployment))]
[TestMethod]
public void PostDeploymentTest()
{
Report.Step(@"Create the mockservices with mountebank", @"Should create the new mockservices");
bool isLoginSuccessful = LoginToEndpoint(pipelineConfigs.APIGatewayBaseUrl, pipelineConfigs.AuthUserName, pipelineConfigs.AuthPassword);
AssertTest.IsTrue(isLoginSuccessful, failMsg: "Login Unsuccessful", passMsg: "Login Successful");
AuthenticationBL authenticationBL = new AuthenticationBL(WebDriver);
var cookie = authenticationBL.GetCookie(pipelineConfigs.CookieName);
string[] mockJsonFiles = Directory.GetFiles(Path.Join(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Tests", "Data", "MockServiceConfigs"), "*.json");
if (mockJsonFiles == null || mockJsonFiles.Length <= 0)
{
AssertTest.IsTrue(false, "No mock json files available");
}
foreach (var mockJsonFile in mockJsonFiles)
{
string mockJsonString = File.ReadAllText(mockJsonFile);
var impostersUrl = $"{pipelineConfigs.APIGatewayBaseUrl}/imposters";
string port = JObject.Parse(mockJsonString)["port"].ToString();
Logger.Info($"Mockservice File: {mockJsonFile}, Port: {port}");
var httpContent = HttpClientUtility.CreateHttpContent(mockJsonString);
var headers = HttpClientUtility.CreateCookieHeader(pipelineConfigs.CookieName, cookie.CookieValue);
string deleteMockServiceApiUrl = $"{ impostersUrl }/{ port}";
Logger.Info($"Delete mockservice Url: {deleteMockServiceApiUrl}");
var deleteResponse = HttpClientUtility.ExecuteAsync(HttpMethod.Delete, deleteMockServiceApiUrl, headers, httpContent).Result;
AssertTest.IsTrue(deleteResponse.IsSuccessStatusCode || deleteResponse.StatusCode == HttpStatusCode.NotFound, failMsg: "Failed to delete the mockservice imposter", passMsg: "Deleted the mockservice imposter");
Logger.Info($"Create mockservice url: {impostersUrl}");
var postCallResponse = HttpClientUtility.ExecuteAsync(HttpMethod.Post, impostersUrl, headers, httpContent).Result;
AssertTest.IsTrue(postCallResponse.IsSuccessStatusCode, failMsg: "Failed to create mockservice", passMsg: "Created mockservice successfully");
}
}
}
}

View File

@ -1,125 +0,0 @@
using System.Net.Http;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Philips.EDI.Foundation.APIGateway.AutomationTest.BusinessLayer;
using Philips.EDI.Foundation.APIGateway.AutomationTest.Models;
using Philips.EDI.Foundation.APIGateway.AutomationTest.Tests.Common;
using Philips.EDI.Foundation.APIGateway.AutomationTest.Utilities;
using Reporters;
using Utilities.Wait;
namespace Philips.EDI.Foundation.APIGateway.AutomationTest.Tests.UITests.AuthenticationTests
{
[TestClass]
public class AuthenticationTests : BaseTest
{
private readonly CommonSteps _commonSteps = new CommonSteps();
[TestCategory(nameof(TestCategory.GatedSanity))]
[TestCategory(nameof(TestCategory.Nightly))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.OnPrem))]
[TestMethod]
public void BrowseEndpointAndLoginWithValidCredentialsTest()
{
_commonSteps.BrowseEndpointAndVerifyLogin(defaultEndpointUrl, pipelineConfigs.AuthUserName, pipelineConfigs.AuthPassword);
}
[TestCategory(nameof(TestCategory.Nightly))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.OnPrem))]
[TestMethod]
public void BrowseEndpointAndLoginWithInvalidCredentialsTest()
{
Report.Step(@"Browse the endpoint url and login with invalid UserName", @"Login should be unsuccessfull");
var isLoginSuccessful = LoginToEndpoint(defaultEndpointUrl, userName: "abc@philips.com", "abc123");
AssertTest.IsFalse(isLoginSuccessful, failMsg: "Login successful with invalid credentials", passMsg: "Unsuccessful Login");
}
[TestCategory(nameof(TestCategory.GatedSanity))]
[TestCategory(nameof(TestCategory.Nightly))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.OnPrem))]
[TestMethod]
public void APICallWithValidCookieTest()
{
_commonSteps.BrowseEndpointAndVerifyLogin(defaultEndpointUrl, pipelineConfigs.AuthUserName, pipelineConfigs.AuthPassword);
Report.Step(@"API call with cookie taken from browser", @"Should get the valid upstream response");
AuthenticationBL authenticationBL = new AuthenticationBL(WebDriver);
var cookie = authenticationBL.GetCookie(pipelineConfigs.CookieName);
AssertTest.IsTrue(cookie != null, failMsg: "Cookie is not available", passMsg: $"Cookie is available, Cookie value: {cookie.CookieValue}");
var headers = HttpClientUtility.CreateCookieHeader(pipelineConfigs.CookieName, cookie.CookieValue);
var responseBody = HttpClientUtility.ExecuteAndGetResponse(HttpMethod.Get, defaultEndpointUrl, headers, null);
AssertTest.IsTrue(responseBody != null && responseBody["status"].ToString().EqualsWithIgnoreCase("success"), failMsg: "No Success response received", passMsg: "Received Success response");
}
[TestCategory(nameof(TestCategory.Nightly))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.OnPrem))]
[TestMethod]
public void APICallInBrowserWithInValidCookieTest()
{
_commonSteps.BrowseEndpointAndVerifyLogin(defaultEndpointUrl, pipelineConfigs.AuthUserName, pipelineConfigs.AuthPassword);
Report.Step(@"Delete/Modify the cookie in browser and browse again the same endpoint url", @"Should get a new cookie and that passes to upstream and get the valid upstream response");
AuthenticationBL authenticationBL = new AuthenticationBL(WebDriver);
var beforeCookie = authenticationBL.GetCookie(pipelineConfigs.CookieName);
beforeCookie.CookieValue = $"abc123{beforeCookie.CookieValue}";
authenticationBL.SetCookie(beforeCookie);
WebDriver.Goto(defaultEndpointUrl);
var afterCookie = authenticationBL.GetCookie(pipelineConfigs.CookieName);
var responseBody = GetResponseFromUI();
AssertTest.AreNotEqual(beforeCookie.CookieValue, afterCookie.CookieValue);
AssertTest.IsTrue(responseBody != null && responseBody["status"].ToString().EqualsWithIgnoreCase("success"), failMsg: "No Success response received after cookie deleted/modified", passMsg: "Received Success response after cookie deleted/modified");
}
[TestCategory(nameof(TestCategory.Nightly))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.OnPrem))]
[TestMethod]
public void AccessUpstreamJustBeforeSessionTimeoutTest()
{
//Make sure to set "OAUTH2_PROXY_COOKIE_REFRESH" = "0h0m15s" (15 seconds) in Oauth proxy service for automaiton
_commonSteps.BrowseEndpointAndVerifyLogin(defaultEndpointUrl, pipelineConfigs.AuthUserName, pipelineConfigs.AuthPassword);
Report.Step($"Wait till before session timeout ({pipelineConfigs.OauthProxyCookieTimeoutInSeconds} seconds)", @"Cookie should not change before the session timeout");
int waitTimeInSeconds = -18;
AssertTest.IsFalse(WaitForGivenTimeAndGetIsCookieChanged(waitTimeInSeconds), failMsg: $"Cookie has changed before the session timeout: {pipelineConfigs.OauthProxyCookieTimeoutInSeconds} and wait time: {pipelineConfigs.OauthProxyCookieTimeoutInSeconds + waitTimeInSeconds}",
passMsg: $"Cookie has not changed before the session timeout: {pipelineConfigs.OauthProxyCookieTimeoutInSeconds} and wait time: {pipelineConfigs.OauthProxyCookieTimeoutInSeconds + waitTimeInSeconds}");
}
[TestCategory(nameof(TestCategory.Nightly))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.OnPrem))]
[TestMethod]
public void AccessUpstreamAfterSessionTimeoutTest()
{
_commonSteps.BrowseEndpointAndVerifyLogin(defaultEndpointUrl, pipelineConfigs.AuthUserName, pipelineConfigs.AuthPassword);
Report.Step($"Wait till after session timeout ({pipelineConfigs.OauthProxyCookieTimeoutInSeconds} seconds)", @"Cookie should change after the session timeout");
int waitTimeInSeconds = 2;
AssertTest.IsTrue(WaitForGivenTimeAndGetIsCookieChanged(waitTimeInSeconds), failMsg: $"Cookie has not changed after the session timeout: {pipelineConfigs.OauthProxyCookieTimeoutInSeconds} and wait time: {pipelineConfigs.OauthProxyCookieTimeoutInSeconds + waitTimeInSeconds}",
passMsg: $"Cookie has changed after the session timeout: {pipelineConfigs.OauthProxyCookieTimeoutInSeconds} and wait time: {pipelineConfigs.OauthProxyCookieTimeoutInSeconds + waitTimeInSeconds}");
}
private bool WaitForGivenTimeAndGetIsCookieChanged(int waitTimeInSeconds)
{
AuthenticationBL authenticationBL = new AuthenticationBL(WebDriver);
var beforeCookie = authenticationBL.GetCookie(pipelineConfigs.CookieName);
int totalWaitTime = pipelineConfigs.OauthProxyCookieTimeoutInSeconds + waitTimeInSeconds;
if (totalWaitTime > 0)
{
Sleep.Seconds(totalWaitTime);
}
WebDriver.Goto(defaultEndpointUrl);
var afterCookie = authenticationBL.GetCookie(pipelineConfigs.CookieName);
AssertTest.IsTrue(true,failMsg:"",passMsg:$"Before cookie:{beforeCookie.CookieValue}\nAfterCookie:{afterCookie.CookieValue}");
return !beforeCookie.CookieValue.Equals(afterCookie.CookieValue);
}
}
}

View File

@ -1,135 +0,0 @@
using Driver.UI.Common;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Philips.EDI.Foundation.APIGateway.AutomationTest.BusinessLayer;
using Philips.EDI.Foundation.APIGateway.AutomationTest.Models;
using Philips.EDI.Foundation.APIGateway.AutomationTest.Tests.Common;
using Philips.EDI.Foundation.APIGateway.AutomationTest.Utilities;
using Reporters;
using System.Net.Http;
using System.Threading.Tasks;
namespace Philips.EDI.Foundation.APIGateway.AutomationTest.Tests.UITests.LogoutTests
{
[TestClass]
public class BrowserLogoutTests : BaseTest
{
#region Tests
CommonSteps _commonSteps = new CommonSteps();
[TestInitialize]
public void BeforeTest()
{
Report.Step(@"Login and open default endpoint url", @"should open the default mockservice page");
_commonSteps.BrowseEndpointAndVerifyLogin(defaultEndpointUrl, pipelineConfigs.AuthUserName, pipelineConfigs.AuthPassword);
}
[TestCategory(nameof(TestCategory.GatedSanity))]
[TestCategory(nameof(TestCategory.Nightly))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.BrowserLogout))]
[TestCategory(nameof(TestCategory.OnPrem))]
[TestMethod]
public void LogoutSuccessTest()
{
Report.Step(@"Call Logout api", @"should be redirected to the login page");
AssertLogoutSuccess();
}
[TestCategory(nameof(TestCategory.Nightly))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.BrowserLogout))]
[TestCategory(nameof(TestCategory.OnPrem))]
[TestMethod]
public async Task ApiRequestBeforeAndAfterLogoutTest()
{
var cookie = FetchAndAssertCookieFromBrowser();
var headers = HttpClientUtility.CreateCookieHeader(pipelineConfigs.CookieName, cookie.CookieValue);
Report.Step(@"API call with cookie taken from browser", @"Should get the valid upstream response");
var responseBeforeLogout = HttpClientUtility.ExecuteAndGetResponse(HttpMethod.Get, defaultEndpointUrl, headers, null);
AssertTest.IsTrue(responseBeforeLogout != null && responseBeforeLogout["status"].ToString().EqualsWithIgnoreCase("success"), failMsg: "No Success response received", passMsg: "Received Success response");
Report.Step(@"Call Logout api", @"should be redirected to the login page");
AssertLogoutSuccess();
Report.Step(@"API call with older cookie taken from browser before logout", @"Should receive the HTML response of the IAM Login page");
var responseAfterLogout = await HttpClientUtility.ExecuteAsync(HttpMethod.Get, defaultEndpointUrl, headers, null);
var body = await responseAfterLogout?.Content?.ReadAsStringAsync();
//Assuming login page is HSDP IAM's Login page
AssertTest.IsTrue(responseAfterLogout != null && responseAfterLogout.IsSuccessStatusCode && body != null && body.Contains("<title>Philips</title>"), failMsg: "IAM login page's title is not displayed", passMsg: "IAM login page's title is displayed");
}
[TestCategory(nameof(TestCategory.Nightly))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.BrowserLogout))]
[TestCategory(nameof(TestCategory.OnPrem))]
[TestMethod]
public void BrowserRequestBeforeandAfterLogoutTest()
{
Report.Step(@"Browser request to the same endpoint", @"Should get the upstream response and login page should not be displayed");
WebDriver.Goto(defaultEndpointUrl);
Assert.IsFalse(IsLoginPageDisplayed());
var responseBody = GetResponseFromUI();
AssertTest.IsTrue(responseBody != null && responseBody["status"].ToString().EqualsWithIgnoreCase("success"), failMsg: "No Success response received", passMsg: "Received Success response");
Report.Step(@"Call Logout api", @"should be redirected to the login page");
AssertLogoutSuccess();
Report.Step(@"Browser request to the default endpoint url", @"Should receive IAM Login page");
WebDriver.Goto(defaultEndpointUrl);
//Assuming login page is HSDP IAM's Login page
AssertTest.IsTrue(IsLoginPageDisplayed(),
failMsg: "Not redirected back to login page", passMsg: "Redirected to login page");
}
[TestCategory(nameof(TestCategory.Nightly))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.BrowserLogout))]
[TestCategory(nameof(TestCategory.OnPrem))]
[TestMethod]
public void LogoutAfterTheSessionTerminatedTest()
{
Report.Step(@"Call Logout api", @"should be redirected to the login page");
AssertLogoutSuccess();
Report.Step(@"Calling Logout api again", @"should be redirected to the login page");
//If we don't specify any redirect-uri it will give 422 Http response code
AssertLogoutSuccess();
}
[TestCategory(nameof(TestCategory.Nightly))]
[TestCategory(nameof(TestCategory.WithoutMultitenancy))]
[TestCategory(nameof(TestCategory.BrowserLogout))]
[TestCategory(nameof(TestCategory.OnPrem))]
[TestMethod]
public void POST_HTTP_CallforLogoutAPITest()
{
Report.Step(@"Perform a POST Http call for Logout API", @"should be redirected to the login page");
AssertTest.IsTrue(_commonSteps.LogoutWithPOST(defaultEndpointUrl, pipelineConfigs.AuthUserName, pipelineConfigs.AuthPassword),"Failed to Logout using PostCall",
"Successfully logged out and redirected to login page with POST call");
}
#endregion Tests
#region Private Methods
private static Cookies FetchAndAssertCookieFromBrowser()
{
Report.Step(@"Get cookie from browser", @"Should get cookie from the current page");
var authenticationBL = new AuthenticationBL(WebDriver);
var cookie = authenticationBL.GetCookie(pipelineConfigs.CookieName);
AssertTest.IsTrue(cookie != null, failMsg: "Cookie is not available", passMsg: $"Cookie is available, Cookie value: {cookie.CookieValue}");
return cookie;
}
private void AssertLogoutSuccess()
{
string GatewayLogoutEndpoint = $"{pipelineConfigs.APIGatewayBaseUrl}{appConfigs.LogoutPath}";
WebDriver.Goto(GatewayLogoutEndpoint);
AssertTest.IsTrue(IsLoginPageDisplayed(),
failMsg: "Logout unsuccessful, not redirected back to login page", passMsg: "Successfully logged out and redirected to login page");
}
#endregion
}
}

View File

@ -1,232 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Philips.EDI.Foundation.APIGateway.AutomationTest.CFUtilites.Models;
using Philips.EDI.Foundation.APIGateway.AutomationTest.Utilities;
using Utilities;
using Utilities.Wait;
namespace Philips.EDI.Foundation.APIGateway.AutomationTest.CFUtilites
{
public class CFUtility
{
private readonly string _cfBaseUrl;
private readonly string _cfUserName;
private readonly string _cfPassword;
private readonly string _cfAccessTokenUrl;
public CFUtility(string cfBaseUrl, string cfUserName, string cfPassword, string cfAccessTokenUrl)
{
_cfBaseUrl = cfBaseUrl;
_cfUserName = cfUserName;
_cfPassword = cfPassword;
_cfAccessTokenUrl = cfAccessTokenUrl;
}
public bool ChangingCFAppState(string orgName, string spaceName, string appName, AppState appState)
{
try
{
string appGuid = GetCFAppGuid(orgName, spaceName, appName);
string postUrl = $"{_cfBaseUrl}/apps/{appGuid }/actions/{appState.ToString()}";
Logger.Info($"CF app state Url: { postUrl}");
using (var apiResponse = HttpClientUtility.ExecuteAsync(HttpMethod.Post, postUrl, CFRequestHeadersWithAuth(), null).Result)
{
if (!apiResponse.IsSuccessStatusCode || apiResponse.Content == null)
{
Logger.Error("Response Code :" + apiResponse.StatusCode.ToString());
Logger.Error($"Failed to change the state of the service to {appState.ToString()} response for : {postUrl}");
return false;
}
bool appCurrentStatus = false;
if (appState == AppState.start || appState == AppState.restart)
{
appCurrentStatus = WaitUtils.WaitUntil(() => GetCFAppStatus(appGuid).EqualsWithIgnoreCase("STARTED"), CFConstants.AppStateChangeTimeoutInSeconds, CFConstants.AppStateChangeCheckFequencyInMilliSeconds);
}
else if (appState == AppState.stop)
{
appCurrentStatus = WaitUtils.WaitUntil(() => GetCFAppStatus(appGuid).EqualsWithIgnoreCase("STOPPED"), CFConstants.AppStateChangeTimeoutInSeconds, CFConstants.AppStateChangeCheckFequencyInMilliSeconds);
}
Sleep.Seconds(10);
return appCurrentStatus;
}
}
catch (Exception ex)
{
Logger.Error(ex.Message);
return false;
}
}
public Dictionary<string, string> GetEnvironmentVariablesFromCFApp(string orgName, string spaceName, string appName)
{
try
{
string appGuid = GetCFAppGuid(orgName, spaceName, appName);
string getUrl = $"{_cfBaseUrl}/apps/{appGuid}/environment_variables";
Logger.Info($"CF Get env url: {getUrl}");
using (HttpResponseMessage apiResponse = HttpClientUtility.ExecuteAsync(HttpMethod.Get, getUrl, CFRequestHeadersWithAuth(), null).Result)
{
if (!apiResponse.IsSuccessStatusCode || apiResponse.Content == null)
{
Logger.Error("Response Code :" + apiResponse.StatusCode.ToString());
Logger.Error($"Failed toget env variables of the application: {appName}");
return null;
}
return GetEnvironmentVariablesFromResponse(apiResponse);
}
}
catch (Exception ex)
{
Logger.Error(ex.Message);
return null;
}
}
public Dictionary<string, string> UpdateEnvironmentVariablesToCFApp(string orgName, string spaceName, string appName, Dictionary<string, string> envVariables)
{
try
{
string appGuid = GetCFAppGuid(orgName, spaceName, appName);
string updateUrl = $"{_cfBaseUrl}/apps/{appGuid}/environment_variables";
Logger.Info($"CF update env url: {updateUrl}");
var envVariablesContent = new CFEnvironmentVariable()
{
EnvironmentVariables = envVariables
};
string json = JsonConvert.SerializeObject(envVariablesContent);
using (HttpResponseMessage apiResponse = PatchEnvironmentVariablesToApp(updateUrl, json))
{
if (!apiResponse.IsSuccessStatusCode || apiResponse.Content == null)
{
Logger.Error("Response Code :" + apiResponse.StatusCode.ToString());
Logger.Error($"Failed to update env variables for the application: {appName}");
return null;
}
ChangingCFAppState(orgName, spaceName, appName, AppState.restart);
return GetEnvironmentVariablesFromResponse(apiResponse);
}
}
catch (Exception ex)
{
Logger.Error(ex.Message);
return null;
}
}
#region private methods
private string GetOrganizationGuid(string orgName)
{
string getOrgsUrl = $"{_cfBaseUrl}/organizations";
Logger.Info($"Get Orgs url: {getOrgsUrl}");
return GetResourceGuid(getOrgsUrl, orgName); ;
}
private string GetSpaceGuid(string orgGuid, string spaceName)
{
string getSpacesUrl = $"{_cfBaseUrl}/spaces?organization_guids={orgGuid}&page=2&per_page=50";
Logger.Info($"Get spaces url: {getSpacesUrl}");
return GetResourceGuid(getSpacesUrl, spaceName);
}
private string GetResourceGuid(string getUrl, string name)
{
var spacesList = HttpClientUtility.ExecuteAndGetResponse(HttpMethod.Get, getUrl, CFRequestHeadersWithAuth(), null)["resources"];
var spaceGuid = spacesList.Where(x => x["name"].ToString().Equals(name, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault()["guid"].ToString();
return spaceGuid;
}
private string GetCFAppGuid(string orgName, string spaceName, string appName)
{
string orgGuid = GetOrganizationGuid(orgName);
string spaceGuid = GetSpaceGuid(orgGuid, spaceName);
string getAppsUrl = $"{_cfBaseUrl}/apps?organization_guids={orgGuid}&space_guids={spaceGuid}&names={appName}";
Logger.Info($"Get apps url: {getAppsUrl}");
return GetResourceGuid(getAppsUrl, appName);
}
private string GetCFAppStatus(string cfAppGuid)
{
string postUrl = _cfBaseUrl + "/apps/" + cfAppGuid;
var apiResponse = HttpClientUtility.ExecuteAndGetResponse(HttpMethod.Get, postUrl, CFRequestHeadersWithAuth(), null);
return apiResponse["state"].ToString();
}
private CFTokenResponse GetCFOauthToken()
{
var postData = new[]
{
new KeyValuePair<string, string>("grant_type","password"),
new KeyValuePair<string, string>("username",_cfUserName),
new KeyValuePair<string, string>("password",_cfPassword)
};
Logger.Info($"CF access token Url: {_cfAccessTokenUrl}");
var token = PostFormUrlEncoded<CFTokenResponse>(_cfAccessTokenUrl, postData).Result;
return token;
}
private async Task<T> PostFormUrlEncoded<T>(string url, IEnumerable<KeyValuePair<string, string>> postData) where T : class
{
using (var httpClient = new HttpClient())
{
string authInfo = "cf" + ":" + "";
authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", authInfo);
using (var content = new FormUrlEncodedContent(postData))
{
HttpResponseMessage response = await httpClient.PostAsync(url, content);
string apiResponseString = response.Content.ReadAsStringAsync().Result;
var tokenResponse = JsonConvert.DeserializeObject<T>(apiResponseString);
return tokenResponse;
}
}
}
private Dictionary<string, string> CFRequestHeadersWithAuth()
{
Dictionary<string, string> headers = new Dictionary<string, string>();
var authToken = GetCFOauthToken();
if (!string.IsNullOrEmpty(authToken.AccessToken.ToString()))
{
headers.Add("Authorization", "Bearer " + authToken.AccessToken);
}
headers.Add("Content-Type", "application/json");
headers.Add("Accept", "application/json");
headers.Add("api-version", "1");
return headers;
}
private static Dictionary<string, string> GetEnvironmentVariablesFromResponse(HttpResponseMessage apiResponse)
{
var envVariables = JObject.Parse(apiResponse.Content.ReadAsStringAsync().Result)["var"].ToString();
return JsonConvert.DeserializeObject<Dictionary<string, string>>(envVariables);
}
private HttpResponseMessage PatchEnvironmentVariablesToApp(string url, string content)
{
var httpClient = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Patch, url);
request.Content = new StringContent(content, Encoding.UTF8, "application/json");
var authToken = GetCFOauthToken();
if (!string.IsNullOrEmpty(authToken.AccessToken.ToString()))
{
request.Headers.Add("Authorization", "Bearer " + authToken.AccessToken);
}
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
request.Headers.Add("api-version", "1");
return httpClient.SendAsync(request).Result;
}
#endregion
}
}

View File

@ -1,9 +0,0 @@
namespace Philips.EDI.Foundation.APIGateway.AutomationTest.CFUtilites.Models
{
public enum AppState
{
start,
stop,
restart
}
}

View File

@ -1,8 +0,0 @@
namespace Philips.EDI.Foundation.APIGateway.AutomationTest.CFUtilites
{
public class CFConstants
{
public const int AppStateChangeTimeoutInSeconds = 30;
public const int AppStateChangeCheckFequencyInMilliSeconds = 500;
}
}

View File

@ -1,11 +0,0 @@
using Newtonsoft.Json;
using System.Collections.Generic;
namespace Philips.EDI.Foundation.APIGateway.AutomationTest.CFUtilites.Models
{
public class CFEnvironmentVariable
{
[JsonProperty("var")]
public Dictionary<string, string> EnvironmentVariables { get; set; }
}
}

View File

@ -1,12 +0,0 @@
using Newtonsoft.Json;
namespace Philips.EDI.Foundation.APIGateway.AutomationTest.CFUtilites.Models
{
public class CFTokenResponse
{
[JsonProperty("access_token")]
public string AccessToken { get; set; }
}
}

View File

@ -1,25 +0,0 @@
using Microsoft.Extensions.Configuration;
using System;
using System.IO;
namespace Philips.EDI.Foundation.APIGateway.AutomationTest.Utilities
{
public class ConfigurationReader
{
public IConfiguration Configuration { get; }
public ConfigurationReader(string jsonFilePath)
{
var builder = new ConfigurationBuilder();
builder.AddJsonFile(jsonFilePath);
Configuration = builder.Build();
}
public ConfigurationReader()
{
var builder = new ConfigurationBuilder();
builder.AddEnvironmentVariables();
Configuration = builder.Build();
}
}
}

View File

@ -1,56 +0,0 @@
using Driver.UI.Interfaces;
using Philips.EDI.Foundation.APIGateway.AutomationTest.Tests.Common;
using System;
using Utilities;
namespace Philips.EDI.Foundation.APIGateway.AutomationTest.Utilities
{
public static class Extensions
{
public static bool EqualsWithIgnoreCase(this string actual, string expected, StringComparison stringComparison = StringComparison.InvariantCultureIgnoreCase)
{
Logger.InfoStartMethod();
try
{
return actual.Equals(expected, stringComparison);
}
catch (Exception ex)
{
Logger.InfoFailedWithException(ex);
throw;
}
}
public static bool StartsWithIgnoreCase(this string actual, string expected, StringComparison stringComparison = StringComparison.InvariantCultureIgnoreCase)
{
Logger.InfoStartMethod();
try
{
return actual.StartsWith(expected, stringComparison);
}
catch (Exception ex)
{
Logger.InfoFailedWithException(ex);
throw;
}
}
public static string TakeScreenshot(this IWebDriverUi webDriver)
{
try
{
string evidenceFolderPath = BaseTest.Report.GetEvidencePath();
string newEvidenceFolderName = BaseTest.Report.GetNewEvidenceFolderName();
string newEvidenceFilePath = string.Format("{0}/{1}.png", evidenceFolderPath, newEvidenceFolderName);
webDriver.TakesScreenShot(newEvidenceFilePath);
return newEvidenceFilePath;
}
catch (Exception ex)
{
Logger.InfoFailedWithException(ex);
throw;
}
}
}
}

View File

@ -1,147 +0,0 @@
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using Driver.Api.HttpClientApi;
using Newtonsoft.Json.Linq;
using Philips.EDI.Foundation.APIGateway.AutomationTest.Models;
using Utilities;
using Utilities.Common;
namespace Philips.EDI.Foundation.APIGateway.AutomationTest.Utilities
{
public class HttpClientUtility
{
private static readonly HttpClient _httpClient = new HttpClient();
private static readonly HttpClient _httpClientWithoutRedirection = new HttpClient( new HttpClientHandler { AllowAutoRedirect = false });
private static readonly HttpClientUtilities _httpClientUtility = new HttpClientUtilities();
public static async Task<HttpResponseMessage> ExecuteAsync(HttpMethod httpMethod, string url, Dictionary<string, string> headers, HttpContent content)
{
return await ExecuteAsync(_httpClient, httpMethod, url, headers, content);
}
public static async Task<HttpResponseMessage> ExecuteAsyncWithoutHttpRedirection(HttpMethod httpMethod, string url, Dictionary<string, string> headers, HttpContent content)
{
return await ExecuteAsync(_httpClientWithoutRedirection, httpMethod, url, headers, content);
}
private static async Task<HttpResponseMessage> ExecuteAsync(HttpClient client,HttpMethod httpMethod, string url, Dictionary<string, string> headers, HttpContent content)
{
try
{
return (httpMethod.ToString()) switch
{
"POST" => await _httpClientUtility.HttpPostAsync(client, url, headers, content),
"PUT" => await _httpClientUtility.HttpPutAsync(client, url, headers, content),
"DELETE" => await _httpClientUtility.HttpDeleteAsync(client, url, headers),
_ => await _httpClientUtility.HttpGetAsyncResp(client, url, headers),//GET
};
}
catch (Exception ex)
{
Logger.InfoFailedWithException(ex);
}
return null;
}
public static StringContent CreateHttpContent(string content, string MediaType = "application/json")
{
Logger.InfoStartMethod();
try
{
return new StringContent(content, Encoding.UTF8, MediaType);
}
catch (Exception ex)
{
Logger.InfoFailedWithException(ex);
throw;
}
}
public static Dictionary<string, string> CreateCookieHeader(string cookieName, string cookieValue)
{
Logger.InfoStartMethod();
try
{
Dictionary<string, string> cookieHeader = new Dictionary<string, string>
{
{ "Cookie", $"{cookieName}={cookieValue}" }
};
return cookieHeader;
}
catch (Exception ex)
{
Logger.InfoFailedWithException(ex);
throw;
}
}
public static Dictionary<string, string> CreateUserAccessTokenHeader(PipelineConfiguration pipelineConfiguration, string tokenType = "access_token")
{
Logger.InfoStartMethod();
try
{
Logger.Info($"Access token url: {pipelineConfiguration.IAMAuthorizationUrl}");
var headers = new Dictionary<string, string>();
headers.Add("Authorization", $"Basic {Convert.ToBase64String(Encoding.ASCII.GetBytes($"{pipelineConfiguration.OauthClientID}:{pipelineConfiguration.OauthClientSecret}"))}");
string content = $"grant_type=password&username={pipelineConfiguration.AuthUserName}&password={pipelineConfiguration.AuthPassword}";
var httpContent = CreateHttpContent(content, "application/x-www-form-urlencoded");
var responseBody = ExecuteAndGetResponse(HttpMethod.Post, pipelineConfiguration.IAMAuthorizationUrl, headers, httpContent);
string authToken = responseBody[tokenType]?.ToString();
if(authToken == null)
{
return null;
}
var userAccessTokenHeader = new Dictionary<string, string>();
userAccessTokenHeader.Add("Authorization", $"Bearer {authToken}");
return userAccessTokenHeader;
}
catch (Exception ex)
{
Logger.InfoFailedWithException(ex);
throw;
}
}
public static Dictionary<string, string> CreateServiceIdAccessTokenHeader(PipelineConfiguration pipelineConfig)
{
Logger.InfoStartMethod();
try
{
string serviceIDAccessToken = CommonFunctionality.GetAccessToken(pipelineConfig.ServiceID, pipelineConfig.ServiceIDPrivateKey, pipelineConfig.IAMAccessTokenUrl, pipelineConfig.IAMAuthorizationUrl);
var serviceIDAccessTokenHeader = new Dictionary<string, string>();
serviceIDAccessTokenHeader.Add("Authorization", $"Bearer {serviceIDAccessToken}");
return serviceIDAccessTokenHeader;
}
catch (Exception ex)
{
Logger.InfoFailedWithException(ex);
throw;
}
}
public static JObject ExecuteAndGetResponse(HttpMethod httpMethod, string url, Dictionary<string, string> headers, HttpContent content)
{
Logger.InfoStartMethod();
try
{
var response = ExecuteAsync(httpMethod, url, headers, content).Result.Content.ReadAsStringAsync().Result;
if (string.IsNullOrEmpty(response))
{
return null;
}
return JObject.Parse(response);
}
catch (Exception ex)
{
Logger.InfoFailedWithException(ex);
throw;
}
}
}
}

View File

@ -1,45 +0,0 @@
using System;
using System.IO;
using System.Reflection;
using Microsoft.Extensions.Configuration;
using Philips.EDI.Foundation.APIGateway.AutomationTest.Models;
using Utilities;
namespace Philips.EDI.Foundation.APIGateway.AutomationTest.Utilities
{
public class Settings
{
private const string _envConfigFile = "Env.json";
private static readonly ConfigurationReader _envConfigReader = new ConfigurationReader(
Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), _envConfigFile));
private static readonly string _executionEnvironment = _envConfigReader.Configuration.GetSection("ExecutionEnvironment").Value;
private static ConfigurationReader _environmentVairableConfigReader;
public static T GetConfiguration<T>(string configSectionName) where T : new()
{
try
{
Logger.Info($"Config section name: {configSectionName}");
T config = new T();
if (configSectionName.StartsWith("AppConfiguration", StringComparison.InvariantCultureIgnoreCase) || _executionEnvironment.Equals(nameof(ExecutionEnvironment.Local), StringComparison.InvariantCultureIgnoreCase))
{
_envConfigReader.Configuration.GetSection(configSectionName).Bind(config);
}
else if (_executionEnvironment.Equals(nameof(ExecutionEnvironment.Production), StringComparison.InvariantCultureIgnoreCase))
{
_environmentVairableConfigReader = new ConfigurationReader();
_environmentVairableConfigReader.Configuration.Bind(config);
}
return config;
}
catch (Exception ex)
{
Logger.InfoFailedWithException(ex);
throw;
}
}
}
}

View File

@ -1,9 +0,0 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Philips.EDI.Foundation.APIGateway.AutomationTest" Version="1.*" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
</ItemGroup>
</Project>

View File

@ -1,27 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
<log4net>
<root>
<level value="ALL" />
<appender-ref ref="file" />
<appender-ref ref="console" />
</root>
<appender name="console" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %level - %message%newline" />
</layout>
</appender>
<appender name="file" type="log4net.Appender.RollingFileAppender">
<file value="AutomationLog.log" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="5" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %level - %message%newline" />
</layout>
</appender>
</log4net>
</configuration>

View File

@ -1,4 +0,0 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v3.1", FrameworkDisplayName = "")]

View File

@ -1,22 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("Philips")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.2.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.2")]
[assembly: System.Reflection.AssemblyProductAttribute("Philips.EDI.Foundation.APIGateway.AutomationTest")]
[assembly: System.Reflection.AssemblyTitleAttribute("Philips.EDI.Foundation.APIGateway.AutomationTest")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.2.0")]
// Generated by the MSBuild WriteCodeFragment class.

View File

@ -1,3 +0,0 @@
is_global = true
build_property.RootNamespace = Philips.EDI.Foundation.APIGateway.AutomationTest
build_property.ProjectDir = c:\git\philips-forks\oauth2-proxy\AutomationTest\