|
| 1 | +using NUnit.Framework; |
| 2 | +using System; |
| 3 | +using System.Collections.Generic; |
| 4 | +using System.Linq; |
| 5 | +using System.Text; |
| 6 | +using System.Threading.Tasks; |
| 7 | +using ApiUtilLib; |
| 8 | +using System.Configuration; |
| 9 | +namespace ApiUtilLibTest |
| 10 | +{ |
| 11 | + [TestFixture] |
| 12 | + public class LiveHttpCallTest |
| 13 | + { |
| 14 | + |
| 15 | + //[Test] |
| 16 | + public static void Http_Call_Test0() |
| 17 | + { |
| 18 | + // application realm |
| 19 | + string realm = "http://example.api.test/token"; |
| 20 | + |
| 21 | + // authorization prefix |
| 22 | + string authPrefix = "Apex_l1_eg";//APEX:must be Apex_l1_eg instead of auth_l1 |
| 23 | + |
| 24 | + // app id and app secret assign to the application |
| 25 | + string appId = "pa-2CPVtaU4DyN9tLZTwJtiY2Cs"; |
| 26 | + string appSecret = "074d6b49ab1837175544f2e0850e9de3360fa1c7"; |
| 27 | + var formData = new ApiUtilLib.ApiList(); |
| 28 | + |
| 29 | + formData.Add("userid", "C9AB42E9-E8CD-E811-810E-00155D464800"); |
| 30 | + formData.Add("key", "W2w6+z5dNeyXzPr08YxUK6syFOk3M62+LLk/S04yZSsEyCjWJ2Fq5iNlrbDo6PNwOV5t6Rblg4FcnxBSBrBNCtYlSVlBJVKO5fY68xXAjUo="); |
| 31 | + // api signing gateway name and path |
| 32 | + string gatewayName = "https://pa.e.api.gov.sg"; //APEX:must be https: xxx |
| 33 | + string apiPath = "api14021live/v1/token"; //APEX:missing main context path: api14021live |
| 34 | + string baseUrl = string.Format("{0}/{1}", gatewayName, apiPath); |
| 35 | + Console.WriteLine("\n>>>baseUrl :: '{0}'<<<", baseUrl); |
| 36 | + Console.WriteLine("\n>>>appId :: '{0}'<<<", appId); |
| 37 | + Console.WriteLine("\n>>>appSecret :: '{0}'<<<", appSecret); |
| 38 | + // authorization header |
| 39 | + var authorizationHeader = ApiAuthorization.Token(realm, authPrefix, HttpMethod.POST, new Uri(baseUrl), appId, appSecret, formData); |
| 40 | + |
| 41 | + Console.WriteLine("\n>>>Authorization Header :: '{0}'<<<", authorizationHeader); |
| 42 | + |
| 43 | + // if the target gateway name is different from signing gateway name |
| 44 | + //string targetGatewayName = "pa.api.gov.sg"; |
| 45 | + string targetBaseUrl = "https://pa.api.gov.sg/api14021live/v1/token"; |
| 46 | + |
| 47 | + |
| 48 | + // this method only for verification only |
| 49 | + // expecting result to be 200 |
| 50 | + var result = ApiAuthorization.HttpRequest(new Uri(targetBaseUrl), authorizationHeader, formData, HttpMethod.POST, ignoreServerCert: true); |
| 51 | + Console.WriteLine(result); |
| 52 | + Console.ReadLine(); |
| 53 | + |
| 54 | + Assert.True(true); |
| 55 | + } |
| 56 | + |
| 57 | + [Test] |
| 58 | + public static void Http_Call_Test1() |
| 59 | + { |
| 60 | + // application realm |
| 61 | + string realm = "http://example.api.test/token"; |
| 62 | + |
| 63 | + // authorization prefix |
| 64 | + string authPrefix = "Apex_l1_eg";//APEX:must be Apex_l1_eg instead of auth_l1 |
| 65 | + |
| 66 | + // app id and app secret assign to the application |
| 67 | + string appId = "mcf-wcc-daxtra-host-xtr-app-id"; |
| 68 | + string appSecret = "23e7e70b265453a95103c756bdb2e9568519eb46"; |
| 69 | + var formData = new ApiUtilLib.ApiList(); |
| 70 | + |
| 71 | + formData.Add("token", "actonomy111\n"); |
| 72 | + formData.Add("challenge", "e82160de-852cf63f-60231922"); |
| 73 | + formData.Add("resource", "10.1.26.72"); |
| 74 | + // api signing gateway name and path |
| 75 | + string gatewayName = "https://mcf.e.api.gov.sg"; //APEX:must be https: xxx |
| 76 | + string apiPath = "mcf-wcc-daxtra-host-xtr/daxtralicence/cvx"; //APEX:missing main context path: api14021live |
| 77 | + string baseUrl = string.Format("{0}/{1}", gatewayName, apiPath); |
| 78 | + Console.WriteLine("\n>>>baseUrl :: '{0}'<<<", baseUrl); |
| 79 | + Console.WriteLine("\n>>>appId :: '{0}'<<<", appId); |
| 80 | + Console.WriteLine("\n>>>appSecret :: '{0}'<<<", appSecret); |
| 81 | + // authorization header |
| 82 | + var authorizationHeader = ApiAuthorization.Token(realm, authPrefix, HttpMethod.POST, new Uri(baseUrl), appId, appSecret, formData); |
| 83 | + |
| 84 | + Console.WriteLine("\n>>>Authorization Header :: '{0}'<<<", authorizationHeader); |
| 85 | + |
| 86 | + // if the target gateway name is different from signing gateway name |
| 87 | + string targetBaseUrl = "https://mcf.api.gov.sg/mcf-wcc-daxtra-host-xtr/daxtralicence/cvx"; |
| 88 | + |
| 89 | + |
| 90 | + // this method only for verification only |
| 91 | + // expecting result to be 200 |
| 92 | + |
| 93 | + var result = ApiAuthorization.HttpRequest(new Uri(targetBaseUrl), authorizationHeader, formData, HttpMethod.POST, ignoreServerCert: true); |
| 94 | + Console.WriteLine(result); |
| 95 | + Console.ReadLine(); |
| 96 | + |
| 97 | + Assert.True(true); |
| 98 | + } |
| 99 | + } |
| 100 | +} |
0 commit comments