Esempio n. 1
0
        public void TestToCanonicalizeHeaderValue2()
        {
            DefaultAuthenticator authenticator = new DefaultAuthenticator(AuthorizationType.V1HMAC, "apiKeyId", "secretApiKey");
            var val1 = authenticator.ToCanonicalizeHeaderValue(" some value  \r\n \n with  some \r\n  spaces ");

            Assert.AreEqual("some value    with  some  spaces", val1);
        }
Esempio n. 2
0
        public void TestToCanonicalizeHeaderValue()
        {
            DefaultAuthenticator authenticator = new DefaultAuthenticator(AuthorizationType.V1HMAC, "apiKeyId", "secretApiKey");

            Assert.AreEqual("aap noot", authenticator.ToCanonicalizeHeaderValue("aap\nnoot  "));
            Assert.AreEqual("aap noot", authenticator.ToCanonicalizeHeaderValue(" aap\r\n  noot"));
        }
Esempio n. 3
0
        ICommunicator CreateCommunicator(int connectTimeout = 50000, int socketTimeout = 50000)
        {
            IConnection      connection       = CreateConnection(connectTimeout, socketTimeout);
            IAuthenticator   authenticator    = new DefaultAuthenticator(AuthorizationType.V1HMAC, "apiKey", "secret");
            MetaDataProvider metaDataProvider = new MetaDataProvider("OnlinePayments");
            var uriBuilder = new UriBuilder("http", "localhost");

            uriBuilder.Port = Port;
            return(Factory.CreateCommunicator(uriBuilder.Uri, connection, authenticator, metaDataProvider));
        }
Esempio n. 4
0
        public void TestCreateAuthenticationSignature2()
        {
            DefaultAuthenticator authenticator = new DefaultAuthenticator(AuthorizationType.V1HMAC, "EC36A74A98D21", "6Kj5HT0MQKC6D8eb7W3lTg71kVKVDSt1");

            string dataToSign = "GET\n\nFri, 06 Jun 2014 13:39:43 GMT\n/v2/9991/tokens/123456789\n";

            string authenticationSignature = authenticator.SignData(dataToSign);

            Assert.AreEqual("Y3E5YaU3oQCt4osEotLGb9W0cMclIzlCpvbaD1KhWxE=", authenticationSignature);
        }
Esempio n. 5
0
        public void TestCreateAuthenticationSignature()
        {
            DefaultAuthenticator authenticator = new DefaultAuthenticator(AuthorizationType.V1HMAC, "apiKeyId", "secretApiKey");

            string dataToSign = "DELETE\napplication/json\nFri, 06 Jun 2014 13:39:43 GMT\nx-gcs-clientmetainfo:processed header value\nx-gcs-customerheader:processed header value\nx-gcs-servermetainfo:processed header value\n/v2/9991/tokens/123456789\n";

            string authenticationSignature = authenticator.SignData(dataToSign);

            Assert.AreEqual("eyLWp/Fa20rXs8UHlhD/13ZuqZkAVMJh9Z71n9TrFxM=", authenticationSignature);
        }
Esempio n. 6
0
        public void TestTotalMinimalExample()
        {
            var authenticator = new DefaultAuthenticator(AuthorizationType.V1HMAC, "5e45c937b9db33ae", "I42Zf4pVnRdroHfuHnRiJjJ2B6+22h0yQt/R3nZR8Xg=");
            IList <RequestHeader> httpHeaders = new List <RequestHeader>();

            httpHeaders.Add(new RequestHeader("User-Agent", "Apache-HttpClient/4.3.4 (java 1.5)"));
            httpHeaders.Add(new RequestHeader("Date", "Fri, 06 Jun 2014 13:39:43 GMT"));
            string signature = authenticator.CreateSimpleAuthenticationSignature(HttpMethod.Get, new Uri("https://payment.preprod.online-payments.com/v2/1/tokens/123456789"), httpHeaders);

            Assert.AreEqual("GCS v1HMAC:5e45c937b9db33ae:UpOoo/pmmj7tW03IbEcw2WtJURFCKL2/J6hqMc+1h1I=", signature);
        }
Esempio n. 7
0
        IClient CreateClient()
        {
            IConnection      connection       = new DefaultConnection(TimeSpan.FromMilliseconds(500000000), 500);
            IAuthenticator   authenticator    = new DefaultAuthenticator(AuthorizationType.V1HMAC, "apiKey", "secret");
            MetaDataProvider metaDataProvider = new MetaDataProvider("OnlinePayments");
            var uriBuilder = new UriBuilder("http", "localhost")
            {
                Port = Port
            };
            ICommunicator communicator = Factory.CreateCommunicator(uriBuilder.Uri, connection, authenticator, metaDataProvider);

            return(Factory.CreateClient(communicator));
        }
Esempio n. 8
0
        public void TestTotalFullExample()
        {
            var authenticator = new DefaultAuthenticator(AuthorizationType.V1HMAC, "5e45c937b9db33ae", "I42Zf4pVnRdroHfuHnRiJjJ2B6+22h0yQt/R3nZR8Xg=");
            IList <RequestHeader> httpHeaders = new List <RequestHeader>();

            httpHeaders.Add(new RequestHeader("User-Agent", "Apache-HttpClient/4.3.4 (java 1.5)"));
            httpHeaders.Add(new RequestHeader("X-GCS-ServerMetaInfo", "processed header value"));
            httpHeaders.Add(new RequestHeader("X-GCS-ClientMetaInfo", "processed header value"));
            httpHeaders.Add(new RequestHeader("Content-Type", "application/json"));
            httpHeaders.Add(new RequestHeader("X-GCS-CustomerHeader", "processed header value"));
            httpHeaders.Add(new RequestHeader("Date", "Fri, 06 Jun 2014 13:39:43 GMT"));
            string signature = authenticator.CreateSimpleAuthenticationSignature(HttpMethod.Delete, new Uri("https://payment.preprod.online-payments.com/v2/1/tokens/123456789"), httpHeaders);

            Assert.AreEqual("GCS v1HMAC:5e45c937b9db33ae:TbiTwCCsGsyFFnfWt5Rreg0cGYJeTiofxjuZNSLUuGo=", signature);
        }
Esempio n. 9
0
        public void TestToDataToSign()
        {
            DefaultAuthenticator  authenticator = new DefaultAuthenticator(AuthorizationType.V1HMAC, "apiKeyId", "secretApiKey");
            IList <RequestHeader> httpHeaders   = new List <RequestHeader>();

            httpHeaders.Add(new RequestHeader("X-GCS-ServerMetaInfo", "{\"platformIdentifier\":\"Windows 7/6.1 Java/1.7 (Oracle Corporation; Java HotSpot(TM) 64-Bit Server VM; 1.7.0_45)\",\"sdkIdentifier\":\"1.0\"}"));
            httpHeaders.Add(new RequestHeader("Content-Type", "application/json"));
            httpHeaders.Add(new RequestHeader("X-GCS-ClientMetaInfo", "{\"aap\",\"noot\"}"));
            httpHeaders.Add(new RequestHeader("User-Agent", "Apache-HttpClient/4.3.4 (java 1.5)"));
            httpHeaders.Add(new RequestHeader("Date", "Mon, 07 Jul 2014 12:12:40 GMT"));
            string dataToSign = authenticator.ToDataToSign(HttpMethod.Post, new Uri("http://localhost:8080/v2/9991/services%20bla/convert/amount?aap=noot&mies=geen%20noot"), httpHeaders);

            string expectedStart =
                "POST\napplication/json\n";
            string expectedEnd =
                "x-gcs-clientmetainfo:{\"aap\",\"noot\"}\nx-gcs-servermetainfo:{\"platformIdentifier\":\"Windows 7/6.1 Java/1.7 (Oracle Corporation; Java HotSpot(TM) 64-Bit Server VM; 1.7.0_45)\",\"sdkIdentifier\":\"1.0\"}\n/v2/9991/services%20bla/convert/amount?aap=noot&mies=geen noot\n";

            string actualStart = dataToSign.Substring(0, 22);
            string actualEnd   = dataToSign.Substring(52, dataToSign.Length - 52);

            Assert.AreEqual(expectedStart, actualStart);
            Assert.AreEqual(expectedEnd, actualEnd);
        }