Exemplo n.º 1
0
        string SignL1(ApiUtilLib.HttpMethod httpMethod)
        {
            var authPrefix = _type == GatewayType.PROXY ? "Apex_l1_eg" : "Apex_l1_ig";

            return(ApiAuthorization.Token(realm:  _realm, authPrefix: authPrefix, httpMethod: httpMethod,
                                          urlPath: new Uri(_signingUrlPath), appId: _appId, secret: _appSecret));
        }
Exemplo n.º 2
0
        string SignL2(ApiUtilLib.HttpMethod httpMethod)
        {
            var authPrefix = _type == GatewayType.PROXY ? "Apex_l2_eg" : "Apex_l2_ig";
            var path       = GetLocalPath(_certFileName);
            var privateKey = ApiAuthorization.PrivateKeyFromP12(path, _certPassPhrase);

            return(ApiAuthorization.Token(realm:  _realm, authPrefix: authPrefix, httpMethod: httpMethod,
                                          urlPath: new Uri(_signingUrlPath), appId: _appId, privateKey: privateKey));
        }
        public void Test_L2_Wrong_Password_Test()
        {
            Assert.Throws <System.Security.Cryptography.CryptographicException>(() =>
            {
                var myPrivateKey = ApiAuthorization.PrivateKeyFromP12(privateCertNameP12, passphrase + "x");

                ApiAuthorization.Token(
                    realm
                    , authPrefixL2
                    , httpMethod
                    , url
                    , appId
                    , privateKey: myPrivateKey
                    );
            });
        }
        public void Test_L2_Basic_Test()
        {
            var expectedTokenL2 = "Api_prefix_l2 realm=\"http://example.api.test/token\",api_prefix_l2_timestamp=\"1502199514462\",api_prefix_l2_nonce=\"-5816789581922453013\",api_prefix_l2_app_id=\"app-id-lpX54CVNltS0ye03v2mQc0b\",api_prefix_l2_signature_method=\"SHA256withRSA\",api_prefix_l2_version=\"1.0\",api_prefix_l2_signature=\"EZuFn/n3dxJ4OA9nkdM3yvw76azvyx/HKptQoWzTNWHxMB/2FyurbbpsSb16yNU4bOzRgHlFTZZzbJeZd211M7tLfRC/YQ1Mc2aIxufG7c7H3/3IZ0WdfHIJlF+XwHOR4U5sjRhbCBwSOZzHp6V2a/nmm+CYTjW2LBHxG7aB1wNI6V1PGDp+ePVr8uoyd4MD9nJj5IqLlljtpWCBUJsa7ZZdXgwbStxAdVA3j2lk3FAH9BzaKTQV0msB50Ou/itAw95pqH4RGrWjcuUETUN82JG154SrT/+hqXlmgsgl+6vui7kyCIGnQjhH+3ZSIp/91nJKW8/1hDcNKWQzuoIS9G23rJzPIuStc1f8y/YvXjUSxNTItb4DcSGwqOs1W8+ejLofW/HDBENhhL66ZZaO0EbJmMWJDp+r7w+RtrlRa2QLsuocuAYAsc8FbhW8SBowIHt/BpuIE21SCfXhbbqYmi0WY+YjJxJ79bNsf7OzH57wQln2Ri6jUtRsCez3rP+714aSAJMLKzJPrsUsiefQDuDjl+g7Fs+Ge5eCv3EOu36qmBEAwvS8oNU8eKa0ZnuXTZrvVEyAAgqQXjv7V4tklKImHMhBv3CqWHGtmxCIqFJuJ71ss81kOJ9pc1otyMzKvSZtVyxaOFgE1hTPfsA6Y5pQayhVikeCMfX8u/uFSmM=\"";

            var authorizationToken = ApiAuthorization.Token(
                realm
                , authPrefixL2
                , httpMethod
                , url
                , appId
                , privateKey: privateKey
                , timestamp: timestamp
                , nonce: nonce
                );

            Assert.AreEqual(expectedTokenL2, authorizationToken);
        }
        public void Test_L1_Basic_Test()
        {
            var expectedTokenL1 = "Api_prefix_l1 realm=\"http://example.api.test/token\",api_prefix_l1_timestamp=\"1502199514462\",api_prefix_l1_nonce=\"-5816789581922453013\",api_prefix_l1_app_id=\"app-id-lpX54CVNltS0ye03v2mQc0b\",api_prefix_l1_signature_method=\"HMACSHA256\",api_prefix_l1_version=\"1.0\",api_prefix_l1_signature=\"loz2Hp2wqiK8RxWjkI6Y6Y4OzmOS/QVPevT8Z43TRM4=\"";

            var authorizationToken = ApiAuthorization.Token(
                realm
                , authPrefixL1
                , httpMethod
                , url
                , appId
                , secret
                , timestamp: timestamp
                , nonce: nonce
                );

            Assert.AreEqual(expectedTokenL1, authorizationToken);
        }
        public void Test_L2_Not_Supported_Cert_Test()
        {
            var fileName = GetLocalPath("Certificates/ssc.alpha.example.com.pem");

            Assert.Throws <System.ArgumentNullException>(() =>
            {
                var myPrivateKey = ApiAuthorization.PrivateKeyFromP12(fileName, passphrase);

                ApiAuthorization.Token(
                    realm
                    , authPrefixL2
                    , httpMethod
                    , url
                    , appId
                    , privateKey: myPrivateKey
                    );
            });
        }
        public void Test_L2_Invalid_FileName_Test()
        {
            var fileName = "Xssc.alpha.example.com.p12";

            Assert.Throws <System.IO.FileNotFoundException>(() =>
            {
                var myPrivateKey = ApiAuthorization.PrivateKeyFromP12(fileName, passphrase);

                ApiAuthorization.Token(
                    realm
                    , authPrefixL2
                    , httpMethod
                    , url
                    , appId
                    , privateKey: myPrivateKey
                    );
            });
        }
Exemplo n.º 8
0
        private static void runTest(TestCase testCase)
        {
            var queryParam = new ApiList();

            foreach (var param in testCase.QueryParams)
            {
                queryParam.Add(param);
            }
            string queryString = queryParam.ToQueryString();

            LoggerManager.Logger.LogInformation($"Test Case {testCase.Name} started. Query string: {queryString}");
            Console.WriteLine($"Test Case {testCase.Name} started.");

            // base URL
            string baseUrl;
            //static string apiPath = "test/l2-eg/v1"; //according to "EDH_BIDWH_HPB_UAT_REST_Scenarios_Conditions_v1.0.xlsx", tab "WebService"
            //v1/entities
            //v1/entity/{uen}
            //v1/entity/{uen}/appointments
            string fullPath;

            switch (testCase.TestMethod)
            {
            case TestMethod.Entities:
                fullPath = $"{apiPath}/entities";
                break;

            case TestMethod.UENs:
                fullPath = $"{apiPath}/entity/{testCase.UEN}";
                break;

            case TestMethod.Appointments:
            default:
                fullPath = $"{apiPath}/entity/{testCase.UEN}/appointments";
                break;
            }

            if (string.IsNullOrEmpty(queryString))
            {
                baseUrl = $"https://{signingGateway}/{fullPath}";
            }
            else
            {
                baseUrl = $"https://{signingGateway}/{fullPath}?{queryString}";
            }

            // authorization header
            var authorizationHeader = ApiAuthorization.Token(realm, authPrefix, HttpMethod.GET, new Uri(baseUrl), appId, null, null, privateKey);

            //target base URL
            string targetBaseUrl;

            if (string.IsNullOrEmpty(queryString))
            {
                targetBaseUrl = $"https://{targetGatewayName}/{fullPath}";
            }
            else
            {
                targetBaseUrl = $"https://{targetGatewayName}/{fullPath}?{queryString}";
            }

            var result = ApiAuthorization.HttpRequest(new Uri(targetBaseUrl), authorizationHeader);

            LoggerManager.Logger.LogInformation($"Test Case {testCase.Name} ended with result: {result}");
            Console.WriteLine($"Test Case {testCase.Name} ended with result: {result}");
        }