public void TestSerializingDeposit()
        {
            var factory      = new JsonRpcFactory();
            var testAssembly = typeof(JsonRpcSignerTest).Assembly;

            TrustlyApiClientSettings settings;

            using (var merchantPrivateKey = testAssembly.GetManifestResourceStream("Trustly.Api.Client.UnitTests.Keys.merchant_private_key.cer"))
            {
                using (var merchantPublicKey = testAssembly.GetManifestResourceStream("Trustly.Api.Client.UnitTests.Keys.merchant_public_key.cer"))
                {
                    settings = TrustlyApiClientSettings
                               .ForTest()
                               .WithCredentialsFromEnv()
                               .WithCertificatesFromStreams(merchantPublicKey, merchantPrivateKey)
                               .AndTrustlyCertificate();
                }
            }

            var requestData = new DepositRequestData
            {
                NotificationURL = "localhost:1000",
                MessageID       = "82bdbc09-7605-4265-b416-1e9549397edd",
                EndUserID       = "127.0.0.1",

                Username = "******",
                Password = "******", // Is not the real password

                Attributes = new DepositRequestDataAttributes
                {
                    Amount    = "100.00",
                    Currency  = "SEK",
                    Country   = "SE",
                    Firstname = "John",
                    Lastname  = "Doe",
                }
            };

            var jsonRpcRequest = factory.Create(requestData, "Deposit", "258a2184-2842-b485-25ca-293525152425");

            var serializer = new Serializer();

            var serialized         = serializer.SerializeData(jsonRpcRequest.Params.Data);
            var expectedSerialized = "AttributesAmount100.00CountrySECurrencySEKFirstnameJohnLastnameDoeEndUserID127.0.0.1MessageID82bdbc09-7605-4265-b416-1e9549397eddNotificationURLlocalhost:1000Passworda6e404c9-7ca8-1204-863d-5642e27c2747Usernameteam_ceres";

            Assert.AreEqual(expectedSerialized, serialized);

            var signer = new JsonRpcSigner(serializer, settings);

            var plaintext         = signer.CreatePlaintext(serialized, jsonRpcRequest.Method, jsonRpcRequest.Params.UUID);
            var expectedPlaintext = "Deposit258a2184-2842-b485-25ca-293525152425AttributesAmount100.00CountrySECurrencySEKFirstnameJohnLastnameDoeEndUserID127.0.0.1MessageID82bdbc09-7605-4265-b416-1e9549397eddNotificationURLlocalhost:1000Passworda6e404c9-7ca8-1204-863d-5642e27c2747Usernameteam_ceres";

            Assert.AreEqual(expectedPlaintext, plaintext);

            signer.Sign(jsonRpcRequest);

            var expectedSignature = "xRed4cLfZs2L5WoJVHiRFvD9yTTvbT0i/BgfhitnTvX7DpfmAz9cmGs3wcTpfYanGlW6hkY7zg7esuaGjPr3NvsWxLGLKBxw97oS7KDmp/FFPnrYulle4MsmKFH5jPB1HMZn2kybXO7a/v1QhVkyKgPGtGSznMBmR8iObbkBGjKbaHdpzwUR2HBK0bomwjIdG7Qx25UMTkMU8a9iNpvwXI71zO9/97DQJK3UiXCicJLNReOTtqcxWL/gUi9h/H7tK6M5kDeNtyRolOhznVZLX/rkFg7exhRvjPk8nEGjMJ3B1O4nEm/xFM0fh4uqfv8QyZrYEzX/K7cfNXflax4n0g==";

            Assert.AreEqual(expectedSignature, jsonRpcRequest.Params.Signature);
        }
Esempio n. 2
0
        public void SetUp()
        {
            var testAssembly = typeof(NotificationTests).Assembly;

            TrustlyApiClientSettings settings;

            using (var trustlyPrivateKey = testAssembly.GetManifestResourceStream("Trustly.Api.Client.UnitTests.Keys.trustly_local_fake_private.pem"))
            {
                using (var trustlyPublicKey = testAssembly.GetManifestResourceStream("Trustly.Api.Client.UnitTests.Keys.trustly_local_fake_public.pem"))
                {
                    using (var merchantPublicKey = testAssembly.GetManifestResourceStream("Trustly.Api.Client.UnitTests.Keys.merchant_public_key.cer"))
                    {
                        // An ugly way to fake as if the "client" is the Trustly server. So we sign the "request" (notification) with Trustly private key.
                        // It is then validated by the same client, with the Trustly public key, as if it is on the other side of the communication.
                        settings = TrustlyApiClientSettings
                                   .ForTest()
                                   .WithoutCredentials()
                                   .WithCertificatesFromStreams(merchantPublicKey, trustlyPrivateKey)
                                   .AndTrustlyCertificateFromStream(trustlyPublicKey);
                    }
                }
            }

            this.client = new TrustlyApiClient(settings);
        }
Esempio n. 3
0
        public AbstractBaseController()
        {
            this.Client = new TrustlyApiClient(TrustlyApiClientSettings.ForDefaultTest());

            this.Client = new TrustlyApiClient(TrustlyApiClientSettings
                                               .ForTest()
                                               .WithCredentialsFromUserHome()
                                               .WithCertificatesFromUserHome()
                                               .AndTrustlyCertificate());
        }
Esempio n. 4
0
        public void TestNullProperties()
        {
            var serializer = new Serializer();

            var testAssembly = typeof(JsonRpcSignerTest).Assembly;

            TrustlyApiClientSettings settings;

            using (var merchantPrivateKey = testAssembly.GetManifestResourceStream("Trustly.Api.Client.UnitTests.Keys.merchant_private_key.cer"))
            {
                using (var merchantPublicKey = testAssembly.GetManifestResourceStream("Trustly.Api.Client.UnitTests.Keys.merchant_public_key.cer"))
                {
                    settings = TrustlyApiClientSettings
                               .ForTest()
                               .WithCredentialsFromEnv()
                               .WithCertificatesFromStreams(merchantPublicKey, merchantPrivateKey)
                               .AndTrustlyCertificate();
                }
            }

            var client = new TrustlyApiClient(settings);
            var signer = new JsonRpcSigner(serializer, settings);

            var rpcResponse = client.CreateResponsePackage("account", "e76ffbe5-e0f9-4402-8689-f868ed2021f8", new NotificationResponse {
                Status = "OK"
            });

            var serialized = serializer.SerializeData(rpcResponse.GetData());

            Assert.AreEqual("statusOK", serialized);

            signer.Sign(rpcResponse);

            Assert.AreEqual(
                "J28IN0yXZN3dlV2ikg4nQKwnP98kso8lzpmuwBcfbXr8i3XeEyydRM4jRwsOOeF0ilGuXyr1Kyb3+1j4mVtgU0SwjVgBHWrYPMegNeykY3meto/aoATH0mvop4Ex1OKO7w/S/ktR2J0J5Npn/EuiKGiVy5GztHYTh9hWmZBCElYPZf4Rsd1CJQJAPlZeAuRcrb5dnbiGJvTEaL/7VLcPT27oqAUefSNb/zNt5yL+wH6BihlkpZ/mtE61lX5OpC46iql6hpsrlOBD3BroYfcwgk1t3YdcNOhVWrmkrlVptGQ/oy6T/LSIKbkG/tJsuV8sl6w1Z31IesK6MZDfSJbcXw==",
                rpcResponse.GetSignature()
                );
        }
Esempio n. 5
0
 public void SetUp()
 {
     this.client = new TrustlyApiClient(TrustlyApiClientSettings.ForDefaultTest());
 }