Beispiel #1
0
        public void ShouldRouteTransaction()
        {
            var transactionHandlerRouter = _serviceProvider.GetService(typeof(TransactionHandlerRouter)) as TransactionHandlerRouter;

            // initialize certificates list
            if (_serviceProvider.GetService(typeof(IOptions <ApplicationSettings>)) is IOptions <ApplicationSettings> applicationSettings)
            {
                applicationSettings.Value.SecuritySettings.PublicCertificates = new List <X509Certificate2>();
            }

            var transaction = new CreateNumber {
                Owner = "A", PhoneNumber = "1", TransactionTime = DateTime.Now
            };
            var json  = JsonConvert.SerializeObject(transaction, new TransactionSerializerSettings());
            var token = new TransactionToken(Encoding.UTF8.GetBytes(json));
            // fake signing
            var signatureField = typeof(TransactionToken).GetField("_signature", BindingFlags.NonPublic | BindingFlags.Instance);

            signatureField.SetValue(token, Encoding.UTF8.GetBytes("1234"));

            var request = new RequestCheckTx {
                Tx = ByteString.CopyFromUtf8(token.ToTokenString())
            };

            // fake context
            var ctor    = typeof(ServerCallContext).GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance).First();
            var context = (ServerCallContext)ctor.Invoke(new object[] { null, "TX", "localhost", DateTime.Now, new Metadata(), CancellationToken.None, null, null });

            var expected        = ResponseHelper.Check.Unauthorized();
            var responseCheckTx = transactionHandlerRouter?.RouteCheckTx(request, context).Result;

            Assert.AreEqual(expected, responseCheckTx);
        }
Beispiel #2
0
        private static async Task Output(BaseTransaction tx, bool copyToClipboard, string party)
        {
            tx.TransactionTime = DateTime.Now;
            var jsonString       = JsonConvert.SerializeObject(tx, new TransactionSerializerSettings());
            var byteArray        = Encoding.UTF8.GetBytes(jsonString);
            var transactionToken = new TransactionToken(byteArray);

            var currentDirectory = Directory.GetCurrentDirectory();

            if (!currentDirectory.Contains("netcoreapp"))
            {
                throw new Exception("Please execute the request creator within netcoreapp2.0 folder.");
            }

            var basePath    = Path.Combine(currentDirectory, "..", "..", "..", "..", "..", "certificates");
            var certificate = new X509Certificate2(Path.Combine(basePath, $"{party}.p12"), "thinktecture");

            transactionToken.Sign(certificate);

            var tokenString = transactionToken.ToTokenString();

            Console.WriteLine("Sending the following tokenstring...");
            Console.WriteLine(tokenString);

            if (copyToClipboard)
            {
                CopyToClipboard(tokenString);
            }

            Console.WriteLine(await MakeRequest(tokenString));
        }