예제 #1
0
        /// <summary>
        /// Implementation of the test itself.
        /// </summary>
        /// <returns>true if the test passes, false otherwise.</returns>
        public override async Task <bool> RunAsync()
        {
            IPAddress NodeIp            = (IPAddress)ArgumentValues["Node IP"];
            int       ClNonCustomerPort = (int)ArgumentValues["clNonCustomer Port"];
            int       ClCustomerPort    = (int)ArgumentValues["clCustomer Port"];

            log.Trace("(NodeIp:'{0}',ClNonCustomerPort:{1},ClCustomerPort:{2})", NodeIp, ClNonCustomerPort, ClCustomerPort);

            bool res = false;

            Passed = false;

            ProtocolClient client = new ProtocolClient();

            try
            {
                MessageBuilder mb = client.MessageBuilder;

                // Step 1
                await client.ConnectAsync(NodeIp, ClNonCustomerPort, true);

                bool establishHomeNodeOk = await client.EstablishHomeNodeAsync();

                // Step 1 Acceptance
                bool step1Ok = establishHomeNodeOk;
                client.CloseConnection();


                // Step 2
                await client.ConnectAsync(NodeIp, ClCustomerPort, true);

                bool startConversationOk = await client.StartConversationAsync();

                Message requestMessage = mb.CreateUpdateProfileRequest(new byte[] { 1, 0, 0 }, "Test Identity", null, 0x12345678, null);
                await client.SendMessageAsync(requestMessage);

                Message responseMessage = await client.ReceiveMessageAsync();

                bool idOk     = responseMessage.Id == requestMessage.Id;
                bool statusOk = responseMessage.Response.Status == Status.ErrorUnauthorized;

                bool updateProfileOk = idOk && statusOk;

                // Step 2 Acceptance
                bool step2Ok = startConversationOk && updateProfileOk;


                Passed = step1Ok && step2Ok;

                res = true;
            }
            catch (Exception e)
            {
                log.Error("Exception occurred: {0}", e.ToString());
            }
            client.Dispose();

            log.Trace("(-):{0}", res);
            return(res);
        }
예제 #2
0
        /// <summary>
        /// Implementation of the test itself.
        /// </summary>
        /// <returns>true if the test passes, false otherwise.</returns>
        public override async Task <bool> RunAsync()
        {
            IPAddress NodeIp            = (IPAddress)ArgumentValues["Node IP"];
            int       ClNonCustomerPort = (int)ArgumentValues["clNonCustomer Port"];
            int       ClCustomerPort    = ClNonCustomerPort;

            log.Trace("(NodeIp:'{0}',ClNonCustomerPort:{1})", NodeIp, ClNonCustomerPort);

            bool res = false;

            Passed = false;

            ProtocolClient client = new ProtocolClient();

            try
            {
                MessageBuilder mb = client.MessageBuilder;

                // Step 1
                await client.ConnectAsync(NodeIp, ClNonCustomerPort, true);

                bool establishHomeNodeOk = await client.EstablishHomeNodeAsync();

                Message requestMessage = mb.CreateCheckInRequest(client.Challenge);
                await client.SendMessageAsync(requestMessage);

                Message responseMessage = await client.ReceiveMessageAsync();

                bool idOk      = responseMessage.Id == requestMessage.Id;
                bool statusOk  = responseMessage.Response.Status == Status.Ok;
                bool checkInOk = idOk && statusOk;

                // Step 1 Acceptance
                Passed = establishHomeNodeOk && checkInOk;

                res = true;
            }
            catch (Exception e)
            {
                log.Error("Exception occurred: {0}", e.ToString());
            }
            client.Dispose();

            log.Trace("(-):{0}", res);
            return(res);
        }
예제 #3
0
        /// <summary>
        /// Implementation of the test itself.
        /// </summary>
        /// <returns>true if the test passes, false otherwise.</returns>
        public override async Task <bool> RunAsync()
        {
            IPAddress NodeIp            = (IPAddress)ArgumentValues["Node IP"];
            int       ClNonCustomerPort = (int)ArgumentValues["clNonCustomer Port"];
            int       ClCustomerPort    = (int)ArgumentValues["clCustomer Port"];

            log.Trace("(NodeIp:'{0}',ClNonCustomerPort:{1},ClCustomerPort:{2})", NodeIp, ClNonCustomerPort, ClCustomerPort);

            bool res = false;

            Passed = false;

            ProtocolClient client = new ProtocolClient();

            try
            {
                MessageBuilder mb             = client.MessageBuilder;
                byte[]         testPubKey     = client.GetIdentityKeys().PublicKey;
                byte[]         testIdentityId = client.GetIdentityId();

                // Step 1
                await client.ConnectAsync(NodeIp, ClNonCustomerPort, true);

                bool establishHomeNodeOk = await client.EstablishHomeNodeAsync();

                // Step 1 Acceptance
                bool step1Ok = establishHomeNodeOk;
                client.CloseConnection();


                // Step 2
                await client.ConnectAsync(NodeIp, ClCustomerPort, true);

                bool checkInOk = await client.CheckInAsync();

                Message requestMessage = mb.CreateUpdateProfileRequest(new byte[] { 1, 0, 0 }, "Test Identity", null, 0x12345678, null);
                await client.SendMessageAsync(requestMessage);

                Message responseMessage = await client.ReceiveMessageAsync();

                bool idOk     = responseMessage.Id == requestMessage.Id;
                bool statusOk = responseMessage.Response.Status == Status.Ok;

                bool updateProfileOk = idOk && statusOk;


                requestMessage = mb.CreateGetIdentityInformationRequest(testIdentityId);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;
                bool isHostedOk = responseMessage.Response.SingleResponse.GetIdentityInformation.IsHosted;
                bool isOnlineOk = responseMessage.Response.SingleResponse.GetIdentityInformation.IsOnline;

                byte[] receivedPubKey = responseMessage.Response.SingleResponse.GetIdentityInformation.IdentityPublicKey.ToByteArray();
                bool   pubKeyOk       = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, testPubKey) == 0;

                bool nameOk      = responseMessage.Response.SingleResponse.GetIdentityInformation.Name == "Test Identity";
                bool extraDataOk = responseMessage.Response.SingleResponse.GetIdentityInformation.ExtraData == "";

                bool getIdentityInfoOk = idOk && statusOk && isHostedOk && isOnlineOk && pubKeyOk && nameOk && extraDataOk;


                byte[] imageData = File.ReadAllBytes(string.Format("images{0}HN04006.jpg", Path.DirectorySeparatorChar));
                requestMessage = mb.CreateUpdateProfileRequest(null, "Test Identity Renamed", imageData, 0x12345678, "a=b");
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;

                bool updateProfileOk2 = idOk && statusOk;

                requestMessage = mb.CreateGetIdentityInformationRequest(testIdentityId, true, true, false);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk       = responseMessage.Id == requestMessage.Id;
                statusOk   = responseMessage.Response.Status == Status.Ok;
                isHostedOk = responseMessage.Response.SingleResponse.GetIdentityInformation.IsHosted;
                isOnlineOk = responseMessage.Response.SingleResponse.GetIdentityInformation.IsOnline;

                receivedPubKey = responseMessage.Response.SingleResponse.GetIdentityInformation.IdentityPublicKey.ToByteArray();
                pubKeyOk       = StructuralComparisons.StructuralComparer.Compare(testPubKey, receivedPubKey) == 0;
                nameOk         = responseMessage.Response.SingleResponse.GetIdentityInformation.Name == "Test Identity Renamed";
                extraDataOk    = responseMessage.Response.SingleResponse.GetIdentityInformation.ExtraData == "a=b";

                byte[] receivedProfileImage   = responseMessage.Response.SingleResponse.GetIdentityInformation.ProfileImage.ToByteArray();
                bool   profileImageOk         = StructuralComparisons.StructuralComparer.Compare(receivedProfileImage, imageData) == 0;
                byte[] receivedThumbnailImage = responseMessage.Response.SingleResponse.GetIdentityInformation.ThumbnailImage.ToByteArray();
                bool   thumbnailImageOk       = receivedThumbnailImage.Length > 0;

                bool getIdentityInfoOk2 = idOk && statusOk && isHostedOk && isOnlineOk && pubKeyOk && nameOk && extraDataOk && profileImageOk && thumbnailImageOk;

                // Step 2 Acceptance
                bool step2Ok = checkInOk && updateProfileOk && getIdentityInfoOk && updateProfileOk2 && getIdentityInfoOk2;


                Passed = step1Ok && step2Ok;

                res = true;
            }
            catch (Exception e)
            {
                log.Error("Exception occurred: {0}", e.ToString());
            }
            client.Dispose();

            log.Trace("(-):{0}", res);
            return(res);
        }
예제 #4
0
        /// <summary>
        /// Implementation of the test itself.
        /// </summary>
        /// <returns>true if the test passes, false otherwise.</returns>
        public override async Task <bool> RunAsync()
        {
            IPAddress NodeIp            = (IPAddress)ArgumentValues["Node IP"];
            int       ClNonCustomerPort = (int)ArgumentValues["clNonCustomer Port"];
            int       ClCustomerPort    = (int)ArgumentValues["clCustomer Port"];

            log.Trace("(NodeIp:'{0}',ClNonCustomerPort:{1},ClCustomerPort:{2})", NodeIp, ClNonCustomerPort, ClCustomerPort);

            bool res = false;

            Passed = false;

            ProtocolClient client = new ProtocolClient();

            try
            {
                MessageBuilder mb = client.MessageBuilder;

                // Step 1
                await client.ConnectAsync(NodeIp, ClNonCustomerPort, true);

                bool establishHomeNodeOk = await client.EstablishHomeNodeAsync();

                // Step 1 Acceptance
                bool step1Ok = establishHomeNodeOk;
                client.CloseConnection();


                // Step 2
                await client.ConnectAsync(NodeIp, ClCustomerPort, true);

                bool checkInOk = await client.CheckInAsync();

                Message requestMessage = mb.CreateCancelHomeNodeAgreementRequest(null);
                await client.SendMessageAsync(requestMessage);

                Message responseMessage = await client.ReceiveMessageAsync();

                bool idOk     = responseMessage.Id == requestMessage.Id;
                bool statusOk = responseMessage.Response.Status == Status.Ok;

                bool cancelHomeNodeAgreementOk = idOk && statusOk;

                // Step 2 Acceptance
                bool step2Ok = checkInOk && cancelHomeNodeAgreementOk;

                client.CloseConnection();

                // Step 3
                await client.ConnectAsync(NodeIp, ClCustomerPort, true);

                bool startConversationOk = await client.StartConversationAsync();

                requestMessage = mb.CreateCheckInRequest(client.Challenge);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk      = responseMessage.Id == requestMessage.Id;
                statusOk  = responseMessage.Response.Status == Status.ErrorNotFound;
                checkInOk = idOk && statusOk;

                // Step 3 Acceptance
                bool step3Ok = startConversationOk && checkInOk;

                client.CloseConnection();



                // Step 4
                await client.ConnectAsync(NodeIp, ClNonCustomerPort, true);

                establishHomeNodeOk = await client.EstablishHomeNodeAsync();

                // Step 4 Acceptance
                bool step4Ok = establishHomeNodeOk;
                client.CloseConnection();



                // Step 5
                await client.ConnectAsync(NodeIp, ClCustomerPort, true);

                checkInOk = await client.CheckInAsync();

                // Step 5 Acceptance
                bool step5Ok = checkInOk;


                Passed = step1Ok && step2Ok && step3Ok && step4Ok && step5Ok;

                res = true;
            }
            catch (Exception e)
            {
                log.Error("Exception occurred: {0}", e.ToString());
            }
            client.Dispose();

            log.Trace("(-):{0}", res);
            return(res);
        }
예제 #5
0
        /// <summary>
        /// Implementation of the test itself.
        /// </summary>
        /// <returns>true if the test passes, false otherwise.</returns>
        public override async Task <bool> RunAsync()
        {
            IPAddress NodeIp      = (IPAddress)ArgumentValues["Node IP"];
            int       PrimaryPort = (int)ArgumentValues["primary Port"];

            log.Trace("(NodeIp:'{0}',PrimaryPort:{1})", NodeIp, PrimaryPort);

            bool res = false;

            Passed = false;

            ProtocolClient clientCallee           = new ProtocolClient();
            ProtocolClient clientCalleeAppService = new ProtocolClient(0, new byte[] { 1, 0, 0 }, clientCallee.GetIdentityKeys());

            ProtocolClient clientCaller           = new ProtocolClient();
            ProtocolClient clientCallerAppService = new ProtocolClient(0, new byte[] { 1, 0, 0 }, clientCaller.GetIdentityKeys());

            try
            {
                MessageBuilder mbCallee           = clientCallee.MessageBuilder;
                MessageBuilder mbCalleeAppService = clientCalleeAppService.MessageBuilder;

                MessageBuilder mbCaller           = clientCaller.MessageBuilder;
                MessageBuilder mbCallerAppService = clientCallerAppService.MessageBuilder;

                // Step 1
                log.Trace("Step 1");
                // Get port list.
                byte[] pubKeyCallee     = clientCallee.GetIdentityKeys().PublicKey;
                byte[] identityIdCallee = clientCallee.GetIdentityId();

                byte[] pubKeyCaller     = clientCaller.GetIdentityKeys().PublicKey;
                byte[] identityIdCaller = clientCaller.GetIdentityId();


                await clientCallee.ConnectAsync(NodeIp, PrimaryPort, false);

                Dictionary <ServerRoleType, uint> rolePorts = new Dictionary <ServerRoleType, uint>();
                bool listPortsOk = await clientCallee.ListNodePorts(rolePorts);

                clientCallee.CloseConnection();


                // Establish home node for identity 1.
                await clientCallee.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool establishHomeNodeOk = await clientCallee.EstablishHomeNodeAsync();

                clientCallee.CloseConnection();


                // Check-in and initialize the profile of identity 1.

                await clientCallee.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClCustomer], true);

                bool checkInOk = await clientCallee.CheckInAsync();

                bool initializeProfileOk = await clientCallee.InitializeProfileAsync("Test Identity", null, 0x12345678, null);


                // Add application service to the current session.
                string serviceName     = "Test Service";
                bool   addAppServiceOk = await clientCallee.AddApplicationServicesAsync(new List <string>() { serviceName });


                // Step 1 Acceptance
                bool step1Ok = listPortsOk && establishHomeNodeOk && checkInOk && initializeProfileOk && addAppServiceOk;

                log.Trace("Step 1: {0}", step1Ok ? "PASSED" : "FAILED");



                // Step 2
                log.Trace("Step 2");
                await clientCaller.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool verifyIdentityOk = await clientCaller.VerifyIdentityAsync();

                Message requestMessage = mbCaller.CreateCallIdentityApplicationServiceRequest(identityIdCallee, "Test Service Invalid");
                await clientCaller.SendMessageAsync(requestMessage);

                Message responseMessage = await clientCaller.ReceiveMessageAsync();

                bool idOk           = responseMessage.Id == requestMessage.Id;
                bool statusOk       = responseMessage.Response.Status == Status.ErrorInvalidValue;
                bool detailsOk      = responseMessage.Response.Details == "serviceName";
                bool callIdentityOk = idOk && statusOk && detailsOk;


                // Step 2 Acceptance
                bool step2Ok = verifyIdentityOk && callIdentityOk;

                log.Trace("Step 2: {0}", step2Ok ? "PASSED" : "FAILED");


                Passed = step1Ok && step2Ok;

                res = true;
            }
            catch (Exception e)
            {
                log.Error("Exception occurred: {0}", e.ToString());
            }
            clientCallee.Dispose();
            clientCalleeAppService.Dispose();
            clientCaller.Dispose();
            clientCallerAppService.Dispose();

            log.Trace("(-):{0}", res);
            return(res);
        }
예제 #6
0
        /// <summary>
        /// Implementation of the test itself.
        /// </summary>
        /// <returns>true if the test passes, false otherwise.</returns>
        public override async Task <bool> RunAsync()
        {
            IPAddress NodeIp      = (IPAddress)ArgumentValues["Node IP"];
            int       PrimaryPort = (int)ArgumentValues["primary Port"];

            log.Trace("(NodeIp:'{0}',PrimaryPort:{1})", NodeIp, PrimaryPort);

            bool res = false;

            Passed = false;

            ProtocolClient clientCallee           = new ProtocolClient();
            ProtocolClient clientCalleeAppService = new ProtocolClient(0, new byte[] { 1, 0, 0 }, clientCallee.GetIdentityKeys());

            ProtocolClient clientCaller           = new ProtocolClient();
            ProtocolClient clientCallerAppService = new ProtocolClient(0, new byte[] { 1, 0, 0 }, clientCaller.GetIdentityKeys());

            try
            {
                MessageBuilder mbCallee           = clientCallee.MessageBuilder;
                MessageBuilder mbCalleeAppService = clientCalleeAppService.MessageBuilder;

                MessageBuilder mbCaller           = clientCaller.MessageBuilder;
                MessageBuilder mbCallerAppService = clientCallerAppService.MessageBuilder;

                // Step 1
                log.Trace("Step 1");
                // Get port list.
                byte[] pubKeyCallee     = clientCallee.GetIdentityKeys().PublicKey;
                byte[] identityIdCallee = clientCallee.GetIdentityId();

                byte[] pubKeyCaller     = clientCaller.GetIdentityKeys().PublicKey;
                byte[] identityIdCaller = clientCaller.GetIdentityId();


                await clientCallee.ConnectAsync(NodeIp, PrimaryPort, false);

                Dictionary <ServerRoleType, uint> rolePorts = new Dictionary <ServerRoleType, uint>();
                bool listPortsOk = await clientCallee.ListNodePorts(rolePorts);

                clientCallee.CloseConnection();


                // Establish home node for identity 1.
                await clientCallee.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool establishHomeNodeOk = await clientCallee.EstablishHomeNodeAsync();

                clientCallee.CloseConnection();


                // Check-in and initialize the profile of identity 1.

                await clientCallee.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClCustomer], true);

                bool checkInOk = await clientCallee.CheckInAsync();

                bool initializeProfileOk = await clientCallee.InitializeProfileAsync("Test Identity", null, 0x12345678, null);


                // Add application service to the current session.
                string serviceName     = "Test Service";
                bool   addAppServiceOk = await clientCallee.AddApplicationServicesAsync(new List <string>() { serviceName });


                // Step 1 Acceptance
                bool step1Ok = listPortsOk && establishHomeNodeOk && checkInOk && initializeProfileOk && addAppServiceOk;

                log.Trace("Step 1: {0}", step1Ok ? "PASSED" : "FAILED");



                // Step 2
                log.Trace("Step 2");
                await clientCaller.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool verifyIdentityOk = await clientCaller.VerifyIdentityAsync();

                Message requestMessage = mbCaller.CreateCallIdentityApplicationServiceRequest(identityIdCallee, serviceName);
                await clientCaller.SendMessageAsync(requestMessage);


                // Step 2 Acceptance
                bool step2Ok = verifyIdentityOk;

                log.Trace("Step 2: {0}", step2Ok ? "PASSED" : "FAILED");



                // Step 3
                log.Trace("Step 3");
                Message nodeRequestMessage = await clientCallee.ReceiveMessageAsync();

                byte[] receivedPubKey = nodeRequestMessage.Request.ConversationRequest.IncomingCallNotification.CallerPublicKey.ToByteArray();
                bool   pubKeyOk       = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, pubKeyCaller) == 0;
                bool   serviceNameOk  = nodeRequestMessage.Request.ConversationRequest.IncomingCallNotification.ServiceName == serviceName;

                bool incomingCallNotificationOk = pubKeyOk && serviceNameOk;

                byte[] calleeToken = nodeRequestMessage.Request.ConversationRequest.IncomingCallNotification.CalleeToken.ToByteArray();

                Message nodeResponseMessage = mbCallee.CreateIncomingCallNotificationResponse(nodeRequestMessage);
                await clientCallee.SendMessageAsync(nodeResponseMessage);


                // Step 3 Acceptance
                bool step3Ok = incomingCallNotificationOk;

                log.Trace("Step 3: {0}", step3Ok ? "PASSED" : "FAILED");


                // Step 4
                log.Trace("Step 4");
                Message responseMessage = await clientCaller.ReceiveMessageAsync();

                bool   idOk        = responseMessage.Id == requestMessage.Id;
                bool   statusOk    = responseMessage.Response.Status == Status.Ok;
                byte[] callerToken = responseMessage.Response.ConversationResponse.CallIdentityApplicationService.CallerToken.ToByteArray();

                bool callIdentityOk = idOk && statusOk;

                // Step 4 Acceptance
                bool step4Ok = callIdentityOk;

                log.Trace("Step 4: {0}", step4Ok ? "PASSED" : "FAILED");



                // Step 5
                // Connect to clAppService and send initialization message.
                await clientCalleeAppService.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClAppService], true);

                await Task.Delay(35 * 1000);

                Message requestMessageAppServiceCallee = mbCalleeAppService.CreateApplicationServiceSendMessageRequest(calleeToken, null);
                await clientCalleeAppService.SendMessageAsync(requestMessageAppServiceCallee);

                // Step 5 Acceptance
                bool step5Ok = true;

                log.Trace("Step 5: {0}", step5Ok ? "PASSED" : "FAILED");



                // Step 6
                // Connect to clAppService and send initialization message.
                await clientCallerAppService.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClAppService], true);

                Message requestMessageAppServiceCaller = mbCallerAppService.CreateApplicationServiceSendMessageRequest(callerToken, null);
                await clientCallerAppService.SendMessageAsync(requestMessageAppServiceCaller);

                Message responseMessageAppServiceCaller = await clientCallerAppService.ReceiveMessageAsync();

                idOk     = responseMessageAppServiceCaller.Id == requestMessageAppServiceCaller.Id;
                statusOk = responseMessageAppServiceCaller.Response.Status == Status.ErrorNotFound;

                bool initAppServiceMessageOk = idOk && statusOk;


                // Step 6 Acceptance
                bool step6Ok = initAppServiceMessageOk;

                log.Trace("Step 6: {0}", step4Ok ? "PASSED" : "FAILED");



                // Step 7
                log.Trace("Step 7");
                Message responseMessageAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync();

                idOk     = responseMessageAppServiceCallee.Id == requestMessageAppServiceCallee.Id;
                statusOk = responseMessageAppServiceCallee.Response.Status == Status.ErrorNotFound;

                bool appServiceSendOk = idOk && statusOk;

                // Step 7 Acceptance
                bool step7Ok = appServiceSendOk;

                log.Trace("Step 7: {0}", step7Ok ? "PASSED" : "FAILED");


                Passed = step1Ok && step2Ok && step3Ok && step4Ok && step5Ok && step6Ok && step7Ok;

                res = true;
            }
            catch (Exception e)
            {
                log.Error("Exception occurred: {0}", e.ToString());
            }
            clientCallee.Dispose();
            clientCalleeAppService.Dispose();
            clientCaller.Dispose();
            clientCallerAppService.Dispose();

            log.Trace("(-):{0}", res);
            return(res);
        }
예제 #7
0
        /// <summary>
        /// Implementation of the test itself.
        /// </summary>
        /// <returns>true if the test passes, false otherwise.</returns>
        public override async Task <bool> RunAsync()
        {
            IPAddress NodeIp            = (IPAddress)ArgumentValues["Node IP"];
            int       ClNonCustomerPort = (int)ArgumentValues["clNonCustomer Port"];
            int       ClCustomerPort    = (int)ArgumentValues["clCustomer Port"];

            log.Trace("(NodeIp:'{0}',ClNonCustomerPort:{1},ClCustomerPort:{2})", NodeIp, ClNonCustomerPort, ClCustomerPort);

            bool res = false;

            Passed = false;

            ProtocolClient client = new ProtocolClient();

            try
            {
                MessageBuilder mb = client.MessageBuilder;

                // Step 1
                await client.ConnectAsync(NodeIp, ClNonCustomerPort, true);

                bool establishHomeNodeOk = await client.EstablishHomeNodeAsync();

                // Step 1 Acceptance
                bool step1Ok = establishHomeNodeOk;
                client.CloseConnection();

                // Step 2
                await client.ConnectAsync(NodeIp, ClCustomerPort, true);

                bool startConversationOk = await client.StartConversationAsync();

                // Invalidate the challenge.
                byte[] challenge = new byte[client.Challenge.Length];
                Array.Copy(client.Challenge, challenge, client.Challenge.Length);
                challenge[0] ^= 0x12;
                Message requestMessage = mb.CreateCheckInRequest(challenge);
                await client.SendMessageAsync(requestMessage);

                Message responseMessage = await client.ReceiveMessageAsync();

                bool idOk      = responseMessage.Id == requestMessage.Id;
                bool statusOk  = responseMessage.Response.Status == Status.ErrorInvalidValue;
                bool detailsOk = responseMessage.Response.Details == "challenge";
                bool checkInOk = idOk && statusOk && detailsOk;

                // Step 2 Acceptance
                bool step2Ok = startConversationOk && checkInOk;

                Passed = step1Ok && step2Ok;

                res = true;
            }
            catch (Exception e)
            {
                log.Error("Exception occurred: {0}", e.ToString());
            }
            client.Dispose();

            log.Trace("(-):{0}", res);
            return(res);
        }
예제 #8
0
        /// <summary>
        /// Implementation of the test itself.
        /// </summary>
        /// <returns>true if the test passes, false otherwise.</returns>
        public override async Task <bool> RunAsync()
        {
            IPAddress NodeIp            = (IPAddress)ArgumentValues["Node IP"];
            int       ClNonCustomerPort = (int)ArgumentValues["clNonCustomer Port"];
            int       ClCustomerPort    = (int)ArgumentValues["clCustomer Port"];

            log.Trace("(NodeIp:'{0}',ClNonCustomerPort:{1},ClCustomerPort:{2})", NodeIp, ClNonCustomerPort, ClCustomerPort);

            bool res = false;

            Passed = false;

            ProtocolClient client = new ProtocolClient();

            try
            {
                MessageBuilder mb             = client.MessageBuilder;
                byte[]         testPubKey     = client.GetIdentityKeys().PublicKey;
                byte[]         testIdentityId = client.GetIdentityId();

                // Step 1
                await client.ConnectAsync(NodeIp, ClNonCustomerPort, true);

                bool establishHomeNodeOk = await client.EstablishHomeNodeAsync();

                // Step 1 Acceptance
                bool step1Ok = establishHomeNodeOk;
                client.CloseConnection();


                // Step 2
                await client.ConnectAsync(NodeIp, ClCustomerPort, true);

                bool checkInOk = await client.CheckInAsync();


                Message requestMessage = mb.CreateUpdateProfileRequest(new byte[] { 1, 0, 0 }, "Test Identity", null, 0x12345678, null);
                await client.SendMessageAsync(requestMessage);

                Message responseMessage = await client.ReceiveMessageAsync();

                bool idOk     = responseMessage.Id == requestMessage.Id;
                bool statusOk = responseMessage.Response.Status == Status.Ok;

                bool updateProfileOk = idOk && statusOk;



                List <string> asList = new List <string>()
                {
                    "a", "b", "c", "d", "a"
                };
                requestMessage = mb.CreateApplicationServiceAddRequest(asList);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;

                bool appServiceAddOk1 = idOk && statusOk;


                requestMessage = mb.CreateGetIdentityInformationRequest(testIdentityId, false, false, true);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;
                bool isHostedOk = responseMessage.Response.SingleResponse.GetIdentityInformation.IsHosted;
                bool isOnlineOk = responseMessage.Response.SingleResponse.GetIdentityInformation.IsOnline;

                byte[] receivedPubKey = responseMessage.Response.SingleResponse.GetIdentityInformation.IdentityPublicKey.ToByteArray();
                bool   pubKeyOk       = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, testPubKey) == 0;

                HashSet <string> expectedAsList = new HashSet <string>()
                {
                    "a", "b", "c", "d"
                };
                HashSet <string> receivedAsList = new HashSet <string>(responseMessage.Response.SingleResponse.GetIdentityInformation.ApplicationServices);
                bool             appServicesOk  = expectedAsList.SetEquals(responseMessage.Response.SingleResponse.GetIdentityInformation.ApplicationServices);


                bool getIdentityInfoOk1 = idOk && statusOk && isHostedOk && isOnlineOk && pubKeyOk && appServicesOk;



                asList = new List <string>()
                {
                    "c", "d", "a", "e"
                };
                requestMessage = mb.CreateApplicationServiceAddRequest(asList);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;

                bool appServiceAddOk2 = idOk && statusOk;


                requestMessage = mb.CreateGetIdentityInformationRequest(testIdentityId, false, false, true);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk       = responseMessage.Id == requestMessage.Id;
                statusOk   = responseMessage.Response.Status == Status.Ok;
                isHostedOk = responseMessage.Response.SingleResponse.GetIdentityInformation.IsHosted;
                isOnlineOk = responseMessage.Response.SingleResponse.GetIdentityInformation.IsOnline;

                receivedPubKey = responseMessage.Response.SingleResponse.GetIdentityInformation.IdentityPublicKey.ToByteArray();
                pubKeyOk       = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, testPubKey) == 0;

                expectedAsList = new HashSet <string>()
                {
                    "a", "b", "c", "d", "e"
                };
                receivedAsList = new HashSet <string>(responseMessage.Response.SingleResponse.GetIdentityInformation.ApplicationServices);
                appServicesOk  = expectedAsList.SetEquals(responseMessage.Response.SingleResponse.GetIdentityInformation.ApplicationServices);


                bool getIdentityInfoOk2 = idOk && statusOk && isHostedOk && isOnlineOk && pubKeyOk && appServicesOk;



                requestMessage = mb.CreateApplicationServiceRemoveRequest("a");
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;

                bool appServiceRemoveOk3 = idOk && statusOk;


                requestMessage = mb.CreateGetIdentityInformationRequest(testIdentityId, false, false, true);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk       = responseMessage.Id == requestMessage.Id;
                statusOk   = responseMessage.Response.Status == Status.Ok;
                isHostedOk = responseMessage.Response.SingleResponse.GetIdentityInformation.IsHosted;
                isOnlineOk = responseMessage.Response.SingleResponse.GetIdentityInformation.IsOnline;

                receivedPubKey = responseMessage.Response.SingleResponse.GetIdentityInformation.IdentityPublicKey.ToByteArray();
                pubKeyOk       = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, testPubKey) == 0;

                expectedAsList = new HashSet <string>()
                {
                    "b", "c", "d", "e"
                };
                receivedAsList = new HashSet <string>(responseMessage.Response.SingleResponse.GetIdentityInformation.ApplicationServices);
                appServicesOk  = expectedAsList.SetEquals(responseMessage.Response.SingleResponse.GetIdentityInformation.ApplicationServices);


                bool getIdentityInfoOk3 = idOk && statusOk && isHostedOk && isOnlineOk && pubKeyOk && appServicesOk;



                requestMessage = mb.CreateApplicationServiceRemoveRequest("a");
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.ErrorNotFound;

                bool appServiceRemoveOk4 = idOk && statusOk;


                requestMessage = mb.CreateGetIdentityInformationRequest(testIdentityId, false, false, true);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk       = responseMessage.Id == requestMessage.Id;
                statusOk   = responseMessage.Response.Status == Status.Ok;
                isHostedOk = responseMessage.Response.SingleResponse.GetIdentityInformation.IsHosted;
                isOnlineOk = responseMessage.Response.SingleResponse.GetIdentityInformation.IsOnline;

                receivedPubKey = responseMessage.Response.SingleResponse.GetIdentityInformation.IdentityPublicKey.ToByteArray();
                pubKeyOk       = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, testPubKey) == 0;

                expectedAsList = new HashSet <string>()
                {
                    "b", "c", "d", "e"
                };
                receivedAsList = new HashSet <string>(responseMessage.Response.SingleResponse.GetIdentityInformation.ApplicationServices);
                appServicesOk  = expectedAsList.SetEquals(responseMessage.Response.SingleResponse.GetIdentityInformation.ApplicationServices);


                bool getIdentityInfoOk4 = idOk && statusOk && isHostedOk && isOnlineOk && pubKeyOk && appServicesOk;



                asList = new List <string>()
                {
                    "d", "1234567890-1234567890-1234567890-1234567890", "a", "e"
                };
                requestMessage = mb.CreateApplicationServiceAddRequest(asList);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.ErrorInvalidValue;
                bool detailsOk = responseMessage.Response.Details == "serviceNames[1]";

                bool appServiceAddOk5 = idOk && statusOk && detailsOk;


                requestMessage = mb.CreateGetIdentityInformationRequest(testIdentityId, false, false, true);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk       = responseMessage.Id == requestMessage.Id;
                statusOk   = responseMessage.Response.Status == Status.Ok;
                isHostedOk = responseMessage.Response.SingleResponse.GetIdentityInformation.IsHosted;
                isOnlineOk = responseMessage.Response.SingleResponse.GetIdentityInformation.IsOnline;

                receivedPubKey = responseMessage.Response.SingleResponse.GetIdentityInformation.IdentityPublicKey.ToByteArray();
                pubKeyOk       = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, testPubKey) == 0;

                expectedAsList = new HashSet <string>()
                {
                    "b", "c", "d", "e"
                };
                receivedAsList = new HashSet <string>(responseMessage.Response.SingleResponse.GetIdentityInformation.ApplicationServices);
                appServicesOk  = expectedAsList.SetEquals(responseMessage.Response.SingleResponse.GetIdentityInformation.ApplicationServices);


                bool getIdentityInfoOk5 = idOk && statusOk && isHostedOk && isOnlineOk && pubKeyOk && appServicesOk;



                asList = new List <string>()
                {
                    "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "a10"
                };
                requestMessage = mb.CreateApplicationServiceAddRequest(asList);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;

                bool appServiceAddOk6 = idOk && statusOk;


                asList = new List <string>()
                {
                    "b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8", "b9", "b10"
                };
                requestMessage = mb.CreateApplicationServiceAddRequest(asList);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;

                bool appServiceAddOk7 = idOk && statusOk;



                requestMessage = mb.CreateGetIdentityInformationRequest(testIdentityId, false, false, true);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk       = responseMessage.Id == requestMessage.Id;
                statusOk   = responseMessage.Response.Status == Status.Ok;
                isHostedOk = responseMessage.Response.SingleResponse.GetIdentityInformation.IsHosted;
                isOnlineOk = responseMessage.Response.SingleResponse.GetIdentityInformation.IsOnline;

                receivedPubKey = responseMessage.Response.SingleResponse.GetIdentityInformation.IdentityPublicKey.ToByteArray();
                pubKeyOk       = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, testPubKey) == 0;

                expectedAsList = new HashSet <string>()
                {
                    "b", "c", "d", "e", "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "a10", "b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8", "b9", "b10"
                };
                receivedAsList = new HashSet <string>(responseMessage.Response.SingleResponse.GetIdentityInformation.ApplicationServices);
                appServicesOk  = expectedAsList.SetEquals(responseMessage.Response.SingleResponse.GetIdentityInformation.ApplicationServices);


                bool getIdentityInfoOk7 = idOk && statusOk && isHostedOk && isOnlineOk && pubKeyOk && appServicesOk;



                asList = new List <string>()
                {
                    "c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "c10", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8", "d9", "d10", "e1", "e2", "e3", "e4", "e5", "e6", "e7", "e8", "e9", "e10"
                };
                requestMessage = mb.CreateApplicationServiceAddRequest(asList);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.ErrorQuotaExceeded;

                bool appServiceAddOk8 = idOk && statusOk;


                requestMessage = mb.CreateGetIdentityInformationRequest(testIdentityId, false, false, true);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk       = responseMessage.Id == requestMessage.Id;
                statusOk   = responseMessage.Response.Status == Status.Ok;
                isHostedOk = responseMessage.Response.SingleResponse.GetIdentityInformation.IsHosted;
                isOnlineOk = responseMessage.Response.SingleResponse.GetIdentityInformation.IsOnline;

                receivedPubKey = responseMessage.Response.SingleResponse.GetIdentityInformation.IdentityPublicKey.ToByteArray();
                pubKeyOk       = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, testPubKey) == 0;

                expectedAsList = new HashSet <string>()
                {
                    "b", "c", "d", "e", "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "a10", "b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8", "b9", "b10"
                };
                receivedAsList = new HashSet <string>(responseMessage.Response.SingleResponse.GetIdentityInformation.ApplicationServices);
                appServicesOk  = expectedAsList.SetEquals(responseMessage.Response.SingleResponse.GetIdentityInformation.ApplicationServices);


                bool getIdentityInfoOk8 = idOk && statusOk && isHostedOk && isOnlineOk && pubKeyOk && appServicesOk;


                // Step 2 Acceptance
                bool step2Ok = checkInOk && updateProfileOk && appServiceAddOk1 && getIdentityInfoOk1 && appServiceAddOk2 && getIdentityInfoOk2 && appServiceRemoveOk3 &&
                               getIdentityInfoOk3 && appServiceRemoveOk4 && getIdentityInfoOk4 && appServiceAddOk5 && getIdentityInfoOk5 && appServiceAddOk6 && appServiceAddOk7 &&
                               getIdentityInfoOk7 && appServiceAddOk8 && getIdentityInfoOk8;


                Passed = step1Ok && step2Ok;

                res = true;
            }
            catch (Exception e)
            {
                log.Error("Exception occurred: {0}", e.ToString());
            }
            client.Dispose();

            log.Trace("(-):{0}", res);
            return(res);
        }
예제 #9
0
        /// <summary>
        /// Implementation of the test itself.
        /// </summary>
        /// <returns>true if the test passes, false otherwise.</returns>
        public override async Task <bool> RunAsync()
        {
            IPAddress NodeIp      = (IPAddress)ArgumentValues["Node IP"];
            int       PrimaryPort = (int)ArgumentValues["primary Port"];

            log.Trace("(NodeIp:'{0}',PrimaryPort:{1})", NodeIp, PrimaryPort);

            bool res = false;

            Passed = false;

            ProtocolClient clientCallee            = new ProtocolClient();
            ProtocolClient clientCallee1AppService = new ProtocolClient(0, new byte[] { 1, 0, 0 }, clientCallee.GetIdentityKeys());
            ProtocolClient clientCallee2AppService = new ProtocolClient(0, new byte[] { 1, 0, 0 }, clientCallee.GetIdentityKeys());

            ProtocolClient clientCaller1           = new ProtocolClient();
            ProtocolClient clientCaller1AppService = new ProtocolClient(0, new byte[] { 1, 0, 0 }, clientCaller1.GetIdentityKeys());

            ProtocolClient clientCaller2           = new ProtocolClient();
            ProtocolClient clientCaller2AppService = new ProtocolClient(0, new byte[] { 1, 0, 0 }, clientCaller2.GetIdentityKeys());

            try
            {
                MessageBuilder mbCallee            = clientCallee.MessageBuilder;
                MessageBuilder mbCallee1AppService = clientCallee1AppService.MessageBuilder;
                MessageBuilder mbCallee2AppService = clientCallee2AppService.MessageBuilder;

                MessageBuilder mbCaller1           = clientCaller1.MessageBuilder;
                MessageBuilder mbCaller1AppService = clientCaller1AppService.MessageBuilder;

                MessageBuilder mbCaller2           = clientCaller2.MessageBuilder;
                MessageBuilder mbCaller2AppService = clientCaller2AppService.MessageBuilder;


                // Step 1
                log.Trace("Step 1");

                byte[] pubKeyCallee     = clientCallee.GetIdentityKeys().PublicKey;
                byte[] identityIdCallee = clientCallee.GetIdentityId();

                byte[] pubKeyCaller1     = clientCaller1.GetIdentityKeys().PublicKey;
                byte[] identityIdCaller1 = clientCaller1.GetIdentityId();

                byte[] pubKeyCaller2     = clientCaller2.GetIdentityKeys().PublicKey;
                byte[] identityIdCaller2 = clientCaller2.GetIdentityId();

                // Get port list.

                await clientCallee.ConnectAsync(NodeIp, PrimaryPort, false);

                Dictionary <ServerRoleType, uint> rolePorts = new Dictionary <ServerRoleType, uint>();
                bool listPortsOk = await clientCallee.ListNodePorts(rolePorts);

                clientCallee.CloseConnection();


                // Establish home node for identity 1.
                await clientCallee.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool establishHomeNodeOk = await clientCallee.EstablishHomeNodeAsync();

                clientCallee.CloseConnection();


                // Check-in and initialize the profile of identity 1.

                await clientCallee.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClCustomer], true);

                bool checkInOk = await clientCallee.CheckInAsync();

                bool initializeProfileOk = await clientCallee.InitializeProfileAsync("Test Identity", null, 0x12345678, null);


                // Add application service to the current session.
                string serviceName     = "Test Service";
                bool   addAppServiceOk = await clientCallee.AddApplicationServicesAsync(new List <string>() { serviceName });


                // Step 1 Acceptance
                bool step1Ok = listPortsOk && establishHomeNodeOk && checkInOk && initializeProfileOk && addAppServiceOk;

                log.Trace("Step 1: {0}", step1Ok ? "PASSED" : "FAILED");



                // Step 2
                log.Trace("Step 2");
                await clientCaller1.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool verifyIdentityOk1 = await clientCaller1.VerifyIdentityAsync();

                Message requestMessage       = mbCaller1.CreateCallIdentityApplicationServiceRequest(identityIdCallee, serviceName);
                uint    initMessageCaller1Id = requestMessage.Id;
                await clientCaller1.SendMessageAsync(requestMessage);


                await clientCaller2.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool verifyIdentityOk2 = await clientCaller2.VerifyIdentityAsync();

                requestMessage = mbCaller2.CreateCallIdentityApplicationServiceRequest(identityIdCallee, serviceName);
                uint initMessageCaller2Id = requestMessage.Id;
                await clientCaller2.SendMessageAsync(requestMessage);



                // Step 2 Acceptance
                bool step2Ok = verifyIdentityOk1 && verifyIdentityOk2;

                log.Trace("Step 2: {0}", step2Ok ? "PASSED" : "FAILED");



                // Step 3
                log.Trace("Step 3");
                Message nodeRequestMessage = await clientCallee.ReceiveMessageAsync();

                byte[] receivedPubKey = nodeRequestMessage.Request.ConversationRequest.IncomingCallNotification.CallerPublicKey.ToByteArray();
                bool   pubKeyOk       = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, pubKeyCaller1) == 0;
                bool   serviceNameOk  = nodeRequestMessage.Request.ConversationRequest.IncomingCallNotification.ServiceName == serviceName;

                bool incomingCallNotificationOk1 = pubKeyOk && serviceNameOk;

                byte[] calleeToken1 = nodeRequestMessage.Request.ConversationRequest.IncomingCallNotification.CalleeToken.ToByteArray();

                Message nodeResponseMessage = mbCallee.CreateIncomingCallNotificationResponse(nodeRequestMessage);
                await clientCallee.SendMessageAsync(nodeResponseMessage);



                nodeRequestMessage = await clientCallee.ReceiveMessageAsync();

                receivedPubKey = nodeRequestMessage.Request.ConversationRequest.IncomingCallNotification.CallerPublicKey.ToByteArray();
                pubKeyOk       = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, pubKeyCaller2) == 0;
                serviceNameOk  = nodeRequestMessage.Request.ConversationRequest.IncomingCallNotification.ServiceName == serviceName;

                bool incomingCallNotificationOk2 = pubKeyOk && serviceNameOk;

                byte[] calleeToken2 = nodeRequestMessage.Request.ConversationRequest.IncomingCallNotification.CalleeToken.ToByteArray();

                nodeResponseMessage = mbCallee.CreateIncomingCallNotificationResponse(nodeRequestMessage);
                await clientCallee.SendMessageAsync(nodeResponseMessage);



                // Connect to clAppService and send initialization message (FIRST connection).
                await clientCallee1AppService.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClAppService], true);

                Message requestMessageAppServiceCallee = mbCallee1AppService.CreateApplicationServiceSendMessageRequest(calleeToken1, null);
                await clientCallee1AppService.SendMessageAsync(requestMessageAppServiceCallee);


                // Connect to clAppService and send initialization message (SECOND connection).
                await clientCallee2AppService.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClAppService], true);

                requestMessageAppServiceCallee = mbCallee2AppService.CreateApplicationServiceSendMessageRequest(calleeToken2, null);
                await clientCallee2AppService.SendMessageAsync(requestMessageAppServiceCallee);


                // Step 3 Acceptance
                bool step3Ok = incomingCallNotificationOk1 && incomingCallNotificationOk2;

                log.Trace("Step 3: {0}", step3Ok ? "PASSED" : "FAILED");



                // Step 4
                log.Trace("Step 4");
                Message responseMessage = await clientCaller1.ReceiveMessageAsync();

                bool   idOk         = responseMessage.Id == initMessageCaller1Id;
                bool   statusOk     = responseMessage.Response.Status == Status.Ok;
                byte[] callerToken1 = responseMessage.Response.ConversationResponse.CallIdentityApplicationService.CallerToken.ToByteArray();

                bool callIdentityOk1 = idOk && statusOk;

                // Connect to clAppService and send initialization message.
                await clientCaller1AppService.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClAppService], true);

                Message requestMessageAppServiceCaller = mbCaller1AppService.CreateApplicationServiceSendMessageRequest(callerToken1, null);
                await clientCaller1AppService.SendMessageAsync(requestMessageAppServiceCaller);

                Message responseMessageAppServiceCaller = await clientCaller1AppService.ReceiveMessageAsync();

                idOk     = responseMessageAppServiceCaller.Id == requestMessageAppServiceCaller.Id;
                statusOk = responseMessageAppServiceCaller.Response.Status == Status.Ok;

                bool initAppServiceMessageOk1 = idOk && statusOk;



                responseMessage = await clientCaller2.ReceiveMessageAsync();

                idOk     = responseMessage.Id == initMessageCaller1Id;
                statusOk = responseMessage.Response.Status == Status.Ok;
                byte[] callerToken2 = responseMessage.Response.ConversationResponse.CallIdentityApplicationService.CallerToken.ToByteArray();

                bool callIdentityOk2 = idOk && statusOk;

                // Connect to clAppService and send initialization message.
                await clientCaller2AppService.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClAppService], true);

                requestMessageAppServiceCaller = mbCaller2AppService.CreateApplicationServiceSendMessageRequest(callerToken2, null);
                await clientCaller2AppService.SendMessageAsync(requestMessageAppServiceCaller);

                responseMessageAppServiceCaller = await clientCaller2AppService.ReceiveMessageAsync();

                idOk     = responseMessageAppServiceCaller.Id == requestMessageAppServiceCaller.Id;
                statusOk = responseMessageAppServiceCaller.Response.Status == Status.Ok;

                bool initAppServiceMessageOk2 = idOk && statusOk;


                // Step 4 Acceptance
                bool step4Ok = callIdentityOk1 && initAppServiceMessageOk1 && callIdentityOk2 && initAppServiceMessageOk2;

                log.Trace("Step 4: {0}", step4Ok ? "PASSED" : "FAILED");



                // Step 5
                log.Trace("Step 5");
                Message responseMessageAppServiceCallee = await clientCallee1AppService.ReceiveMessageAsync();

                idOk     = responseMessageAppServiceCallee.Id == requestMessageAppServiceCallee.Id;
                statusOk = responseMessageAppServiceCallee.Response.Status == Status.Ok;

                bool typeOk = (responseMessageAppServiceCallee.MessageTypeCase == Message.MessageTypeOneofCase.Response) &&
                              (responseMessageAppServiceCallee.Response.ConversationTypeCase == Response.ConversationTypeOneofCase.SingleResponse) &&
                              (responseMessageAppServiceCallee.Response.SingleResponse.ResponseTypeCase == SingleResponse.ResponseTypeOneofCase.ApplicationServiceSendMessage);

                bool appServiceSendOk1 = idOk && statusOk && typeOk;


                responseMessageAppServiceCallee = await clientCallee2AppService.ReceiveMessageAsync();

                idOk     = responseMessageAppServiceCallee.Id == requestMessageAppServiceCallee.Id;
                statusOk = responseMessageAppServiceCallee.Response.Status == Status.Ok;

                typeOk = (responseMessageAppServiceCallee.MessageTypeCase == Message.MessageTypeOneofCase.Response) &&
                         (responseMessageAppServiceCallee.Response.ConversationTypeCase == Response.ConversationTypeOneofCase.SingleResponse) &&
                         (responseMessageAppServiceCallee.Response.SingleResponse.ResponseTypeCase == SingleResponse.ResponseTypeOneofCase.ApplicationServiceSendMessage);

                bool appServiceSendOk2 = idOk && statusOk && typeOk;

                // Step 5 Acceptance
                bool step5Ok = appServiceSendOk1 && appServiceSendOk2;

                log.Trace("Step 5: {0}", step5Ok ? "PASSED" : "FAILED");



                // Step 6
                log.Trace("Step 6");
                string caller1Message1 = "Message #1 to callee from caller1.";
                byte[] messageBytes    = Encoding.UTF8.GetBytes(caller1Message1);
                requestMessageAppServiceCaller = mbCaller1AppService.CreateApplicationServiceSendMessageRequest(callerToken1, messageBytes);
                uint callerMessage1Id = requestMessageAppServiceCaller.Id;
                await clientCaller1AppService.SendMessageAsync(requestMessageAppServiceCaller);


                // Step 6 Acceptance
                bool step6Ok = true;

                log.Trace("Step 6: {0}", step6Ok ? "PASSED" : "FAILED");


                // Step 7
                log.Trace("Step 7");
                // Receive message #1.
                Message nodeRequestAppServiceCallee = await clientCallee1AppService.ReceiveMessageAsync();

                byte[] receivedVersion = nodeRequestAppServiceCallee.Request.SingleRequest.Version.ToByteArray();
                bool   versionOk       = StructuralComparisons.StructuralComparer.Compare(receivedVersion, new byte[] { 1, 0, 0 }) == 0;

                typeOk = (nodeRequestAppServiceCallee.MessageTypeCase == Message.MessageTypeOneofCase.Request) &&
                         (nodeRequestAppServiceCallee.Request.ConversationTypeCase == Request.ConversationTypeOneofCase.SingleRequest) &&
                         (nodeRequestAppServiceCallee.Request.SingleRequest.RequestTypeCase == SingleRequest.RequestTypeOneofCase.ApplicationServiceReceiveMessageNotification);

                string receivedMessage = Encoding.UTF8.GetString(nodeRequestAppServiceCallee.Request.SingleRequest.ApplicationServiceReceiveMessageNotification.Message.ToByteArray());
                bool   messageOk       = receivedMessage == caller1Message1;

                bool receiveMessageOk = versionOk && typeOk && messageOk;


                // ACK message #1.
                Message nodeResponseAppServiceCallee = mbCallee1AppService.CreateApplicationServiceReceiveMessageNotificationResponse(nodeRequestAppServiceCallee);
                await clientCallee1AppService.SendMessageAsync(nodeResponseAppServiceCallee);



                // Send invalid message - over the FIRST connection with token from the SECOND connection.
                await Task.Delay(3000);

                string calleeMessage = "Invalid Message";
                messageBytes = Encoding.UTF8.GetBytes(calleeMessage);
                requestMessageAppServiceCallee = mbCallee1AppService.CreateApplicationServiceSendMessageRequest(calleeToken2, messageBytes);
                await clientCallee1AppService.SendMessageAsync(requestMessageAppServiceCallee);

                Message responseAppServiceCallee = await clientCallee1AppService.ReceiveMessageAsync();

                idOk     = responseAppServiceCallee.Id == requestMessageAppServiceCallee.Id;
                statusOk = responseAppServiceCallee.Response.Status == Status.ErrorNotFound;

                bool sendMessageOk = idOk && statusOk;


                // Step 7 Acceptance
                bool step7Ok = sendMessageOk;

                log.Trace("Step 7: {0}", step7Ok ? "PASSED" : "FAILED");


                // Step 8
                log.Trace("Step 8");
                await Task.Delay(3000);

                string caller2Message1 = "Message #1 to callee from caller2.";
                messageBytes = Encoding.UTF8.GetBytes(caller2Message1);
                requestMessageAppServiceCaller = mbCaller2AppService.CreateApplicationServiceSendMessageRequest(callerToken2, messageBytes);

                // Either the third client is disconnected and this should prevent sending a message or receiving a response,
                // OR just the relay was destroyed and the client will receive error not found.
                bool disconnectOk = false;
                messageOk = false;
                try
                {
                    await clientCaller2AppService.SendMessageAsync(requestMessageAppServiceCaller);

                    responseMessage = await clientCaller2AppService.ReceiveMessageAsync();

                    idOk      = responseMessage.Id == requestMessageAppServiceCaller.Id;
                    statusOk  = responseMessage.Response.Status == Status.ErrorNotFound;
                    messageOk = idOk && statusOk;
                }
                catch
                {
                    log.Trace("Expected exception occurred.");
                    disconnectOk = true;
                }

                // Step 8 Acceptance
                bool step8Ok = disconnectOk || messageOk;

                log.Trace("Step 8: {0}", step8Ok ? "PASSED" : "FAILED");


                // Step 9
                log.Trace("Step 9");

                // Receive ACK message #1.
                responseMessageAppServiceCaller = await clientCaller1AppService.ReceiveMessageAsync();

                idOk            = responseMessageAppServiceCaller.Id == callerMessage1Id;
                statusOk        = responseMessageAppServiceCaller.Response.Status == Status.Ok;
                receivedVersion = responseMessageAppServiceCaller.Response.SingleResponse.Version.ToByteArray();
                versionOk       = StructuralComparisons.StructuralComparer.Compare(receivedVersion, new byte[] { 1, 0, 0 }) == 0;

                bool receiveAckOk = idOk && statusOk && versionOk;

                // Step 9 Acceptance
                bool step9Ok = receiveAckOk;

                log.Trace("Step 9: {0}", step9Ok ? "PASSED" : "FAILED");

                Passed = step1Ok && step2Ok && step3Ok && step4Ok && step5Ok && step6Ok && step7Ok && step8Ok && step9Ok;

                res = true;
            }
            catch (Exception e)
            {
                log.Error("Exception occurred: {0}", e.ToString());
            }
            clientCallee.Dispose();
            clientCallee1AppService.Dispose();
            clientCallee2AppService.Dispose();
            clientCaller1.Dispose();
            clientCaller1AppService.Dispose();
            clientCaller2.Dispose();
            clientCaller2AppService.Dispose();

            log.Trace("(-):{0}", res);
            return(res);
        }
예제 #10
0
        /// <summary>
        /// Implementation of the test itself.
        /// </summary>
        /// <returns>true if the test passes, false otherwise.</returns>
        public override async Task <bool> RunAsync()
        {
            IPAddress NodeIp            = (IPAddress)ArgumentValues["Node IP"];
            int       ClNonCustomerPort = (int)ArgumentValues["clNonCustomer Port"];
            int       ClCustomerPort    = (int)ArgumentValues["clCustomer Port"];

            log.Trace("(NodeIp:'{0}',ClNonCustomerPort:{1},ClCustomerPort:{2})", NodeIp, ClNonCustomerPort, ClCustomerPort);

            bool res = false;

            Passed = false;

            ProtocolClient client = new ProtocolClient();

            try
            {
                MessageBuilder mb             = client.MessageBuilder;
                byte[]         testIdentityId = client.GetIdentityId();

                // Step 1
                await client.ConnectAsync(NodeIp, ClNonCustomerPort, true);

                bool establishHomeNodeOk = await client.EstablishHomeNodeAsync();

                // Step 1 Acceptance
                bool step1Ok = establishHomeNodeOk;
                client.CloseConnection();


                // Step 2
                await client.ConnectAsync(NodeIp, ClCustomerPort, true);

                bool checkInOk = await client.CheckInAsync();

                byte[]  newNodeId      = Encoding.UTF8.GetBytes("test");
                Message requestMessage = mb.CreateCancelHomeNodeAgreementRequest(newNodeId);
                await client.SendMessageAsync(requestMessage);

                Message responseMessage = await client.ReceiveMessageAsync();

                bool idOk      = responseMessage.Id == requestMessage.Id;
                bool statusOk  = responseMessage.Response.Status == Status.ErrorInvalidValue;
                bool detailsOk = responseMessage.Response.Details == "newHomeNodeNetworkId";

                bool cancelAgreementOk = idOk && statusOk && detailsOk;

                // Step 2 Acceptance
                bool step2Ok = checkInOk && cancelAgreementOk;


                Passed = step1Ok && step2Ok;

                res = true;
            }
            catch (Exception e)
            {
                log.Error("Exception occurred: {0}", e.ToString());
            }
            client.Dispose();

            log.Trace("(-):{0}", res);
            return(res);
        }
예제 #11
0
        /// <summary>
        /// Implementation of the test itself.
        /// </summary>
        /// <returns>true if the test passes, false otherwise.</returns>
        public override async Task <bool> RunAsync()
        {
            IPAddress NodeIp            = (IPAddress)ArgumentValues["Node IP"];
            int       ClNonCustomerPort = (int)ArgumentValues["clNonCustomer Port"];

            log.Trace("(NodeIp:'{0}',ClNonCustomerPort:{1})", NodeIp, ClNonCustomerPort);

            bool res = false;

            Passed = false;

            ProtocolClient client1 = new ProtocolClient();
            ProtocolClient client2 = new ProtocolClient();

            try
            {
                MessageBuilder mb1         = client1.MessageBuilder;
                MessageBuilder mb2         = client2.MessageBuilder;
                byte[]         identityId1 = client1.GetIdentityId();

                // Step 1
                await client1.ConnectAsync(NodeIp, ClNonCustomerPort, true);

                bool homeNodeOk = await client1.EstablishHomeNodeAsync();

                client1.CloseConnection();

                // Step 1 Acceptance
                bool step1Ok = homeNodeOk;


                // Step 2
                await client2.ConnectAsync(NodeIp, ClNonCustomerPort, true);

                bool verifyIdentityOk = await client2.VerifyIdentityAsync();

                Message requestMessage = mb2.CreateCallIdentityApplicationServiceRequest(identityId1, "Test Service");
                await client2.SendMessageAsync(requestMessage);

                Message responseMessage = await client2.ReceiveMessageAsync();

                bool idOk           = responseMessage.Id == requestMessage.Id;
                bool statusOk       = responseMessage.Response.Status == Status.ErrorUninitialized;
                bool callIdentityOk = idOk && statusOk;

                // Step 2 Acceptance
                bool step2Ok = verifyIdentityOk && callIdentityOk;


                Passed = step1Ok && step2Ok;

                res = true;
            }
            catch (Exception e)
            {
                log.Error("Exception occurred: {0}", e.ToString());
            }
            client1.Dispose();
            client2.Dispose();

            log.Trace("(-):{0}", res);
            return(res);
        }
예제 #12
0
        /// <summary>
        /// Implementation of the test itself.
        /// </summary>
        /// <returns>true if the test passes, false otherwise.</returns>
        public async Task <bool> RunAsyncInternal(int Index)
        {
            IPAddress NodeIp      = (IPAddress)ArgumentValues["Node IP"];
            int       PrimaryPort = (int)ArgumentValues["primary Port"];

            log.Trace("(NodeIp:'{0}',PrimaryPort:{1},Index:{2})", NodeIp, PrimaryPort, Index);

            bool res = false;

            PassedArray[Index] = false;

            ProtocolClient clientCallee           = new ProtocolClient();
            ProtocolClient clientCalleeAppService = new ProtocolClient(0, new byte[] { 1, 0, 0 }, clientCallee.GetIdentityKeys());

            ProtocolClient clientCaller           = new ProtocolClient();
            ProtocolClient clientCallerAppService = new ProtocolClient(0, new byte[] { 1, 0, 0 }, clientCaller.GetIdentityKeys());

            try
            {
                MessageBuilder mbCallee           = clientCallee.MessageBuilder;
                MessageBuilder mbCalleeAppService = clientCalleeAppService.MessageBuilder;

                MessageBuilder mbCaller           = clientCaller.MessageBuilder;
                MessageBuilder mbCallerAppService = clientCallerAppService.MessageBuilder;

                // Step 1
                log.Trace("Step 1");
                // Get port list.
                byte[] pubKeyCallee     = clientCallee.GetIdentityKeys().PublicKey;
                byte[] identityIdCallee = clientCallee.GetIdentityId();

                byte[] pubKeyCaller     = clientCaller.GetIdentityKeys().PublicKey;
                byte[] identityIdCaller = clientCaller.GetIdentityId();


                await clientCallee.ConnectAsync(NodeIp, PrimaryPort, false);

                Dictionary <ServerRoleType, uint> rolePorts = new Dictionary <ServerRoleType, uint>();
                bool listPortsOk = await clientCallee.ListNodePorts(rolePorts);

                clientCallee.CloseConnection();


                // Establish home node for identity 1.
                await clientCallee.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool establishHomeNodeOk = await clientCallee.EstablishHomeNodeAsync();

                clientCallee.CloseConnection();


                // Check-in and initialize the profile of identity 1.

                await clientCallee.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClCustomer], true);

                bool checkInOk = await clientCallee.CheckInAsync();

                bool initializeProfileOk = await clientCallee.InitializeProfileAsync("Test Identity", null, 0x12345678, null);


                // Add application service to the current session.
                string serviceName     = "Test Service";
                bool   addAppServiceOk = await clientCallee.AddApplicationServicesAsync(new List <string>() { serviceName });


                // Step 1 Acceptance
                bool step1Ok = listPortsOk && establishHomeNodeOk && checkInOk && initializeProfileOk && addAppServiceOk;

                log.Trace("Step 1: {0}", step1Ok ? "PASSED" : "FAILED");



                // Step 2
                log.Trace("Step 2");
                await clientCaller.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool verifyIdentityOk = await clientCaller.VerifyIdentityAsync();

                Message requestMessage = mbCaller.CreateCallIdentityApplicationServiceRequest(identityIdCallee, serviceName);
                await clientCaller.SendMessageAsync(requestMessage);


                // Step 2 Acceptance
                bool step2Ok = verifyIdentityOk;

                log.Trace("Step 2: {0}", step2Ok ? "PASSED" : "FAILED");



                // Step 3
                log.Trace("Step 3");
                Message nodeRequestMessage = await clientCallee.ReceiveMessageAsync();

                byte[] receivedPubKey = nodeRequestMessage.Request.ConversationRequest.IncomingCallNotification.CallerPublicKey.ToByteArray();
                bool   pubKeyOk       = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, pubKeyCaller) == 0;
                bool   serviceNameOk  = nodeRequestMessage.Request.ConversationRequest.IncomingCallNotification.ServiceName == serviceName;

                bool incomingCallNotificationOk = pubKeyOk && serviceNameOk;

                byte[] calleeToken = nodeRequestMessage.Request.ConversationRequest.IncomingCallNotification.CalleeToken.ToByteArray();

                Message nodeResponseMessage = mbCallee.CreateIncomingCallNotificationResponse(nodeRequestMessage);
                await clientCallee.SendMessageAsync(nodeResponseMessage);


                // Connect to clAppService and send initialization message.
                await clientCalleeAppService.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClAppService], true);

                Message requestMessageAppServiceCallee = mbCalleeAppService.CreateApplicationServiceSendMessageRequest(calleeToken, null);
                await clientCalleeAppService.SendMessageAsync(requestMessageAppServiceCallee);


                // Step 3 Acceptance
                bool step3Ok = incomingCallNotificationOk;

                log.Trace("Step 3: {0}", step3Ok ? "PASSED" : "FAILED");


                // Step 4
                log.Trace("Step 4");
                Message responseMessage = await clientCaller.ReceiveMessageAsync();

                bool   idOk        = responseMessage.Id == requestMessage.Id;
                bool   statusOk    = responseMessage.Response.Status == Status.Ok;
                byte[] callerToken = responseMessage.Response.ConversationResponse.CallIdentityApplicationService.CallerToken.ToByteArray();

                bool callIdentityOk = idOk && statusOk;

                // Connect to clAppService and send initialization message.
                await clientCallerAppService.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClAppService], true);

                Message requestMessageAppServiceCaller = mbCallerAppService.CreateApplicationServiceSendMessageRequest(callerToken, null);
                await clientCallerAppService.SendMessageAsync(requestMessageAppServiceCaller);

                Message responseMessageAppServiceCaller = await clientCallerAppService.ReceiveMessageAsync();

                idOk     = responseMessageAppServiceCaller.Id == requestMessageAppServiceCaller.Id;
                statusOk = responseMessageAppServiceCaller.Response.Status == Status.Ok;

                bool initAppServiceMessageOk = idOk && statusOk;

                // And close connection to clNonCustomer port.
                clientCaller.CloseConnection();


                // Step 4 Acceptance
                bool step4Ok = callIdentityOk && initAppServiceMessageOk;

                log.Trace("Step 4: {0}", step4Ok ? "PASSED" : "FAILED");



                // Step 5
                log.Trace("Step 5");
                Message responseMessageAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync();

                idOk     = responseMessageAppServiceCallee.Id == requestMessageAppServiceCallee.Id;
                statusOk = responseMessageAppServiceCallee.Response.Status == Status.Ok;

                bool typeOk = (responseMessageAppServiceCallee.MessageTypeCase == Message.MessageTypeOneofCase.Response) &&
                              (responseMessageAppServiceCallee.Response.ConversationTypeCase == Response.ConversationTypeOneofCase.SingleResponse) &&
                              (responseMessageAppServiceCallee.Response.SingleResponse.ResponseTypeCase == SingleResponse.ResponseTypeOneofCase.ApplicationServiceSendMessage);

                bool appServiceSendOk = idOk && statusOk && typeOk;

                // Step 5 Acceptance
                bool step5Ok = appServiceSendOk;

                log.Trace("Step 5: {0}", step5Ok ? "PASSED" : "FAILED");



                // Step 6
                UnfinishedRequestCounter callerCounter = new UnfinishedRequestCounter()
                {
                    Name = string.Format("Caller-{0}", Index)
                };
                UnfinishedRequestCounter calleeCounter = new UnfinishedRequestCounter()
                {
                    Name = string.Format("Callee-{0}", Index)
                };
                SemaphoreSlim callerWriteLock = new SemaphoreSlim(1);
                SemaphoreSlim calleeWriteLock = new SemaphoreSlim(1);

                Task <byte[]> messageReceivingTaskCaller = MessageReceivingLoop(clientCallerAppService, mbCallerAppService, "CallerReceiving", callerWriteLock, callerCounter);
                Task <byte[]> messageReceivingTaskCallee = MessageReceivingLoop(clientCalleeAppService, mbCalleeAppService, "CalleeReceiving", calleeWriteLock, calleeCounter);

                Task <byte[]> messageSendingTaskCaller = MessageSendingLoop(clientCallerAppService, mbCallerAppService, "CallerSending", callerToken, callerWriteLock, callerCounter);
                Task <byte[]> messageSendingTaskCallee = MessageSendingLoop(clientCalleeAppService, mbCalleeAppService, "CalleeSending", calleeToken, calleeWriteLock, calleeCounter);

                byte[] callerSendMessageHash = messageSendingTaskCaller.Result;
                byte[] calleeSendMessageHash = messageSendingTaskCallee.Result;

                byte[] callerReceiveMessageHash = messageReceivingTaskCaller.Result;
                byte[] calleeReceiveMessageHash = messageReceivingTaskCallee.Result;


                bool callerMessageHashOk = StructuralComparisons.StructuralComparer.Compare(callerSendMessageHash, calleeReceiveMessageHash) == 0;
                bool calleeMessageHashOk = StructuralComparisons.StructuralComparer.Compare(calleeSendMessageHash, callerReceiveMessageHash) == 0;


                // Step 6 Acceptance
                bool step6Ok = callerMessageHashOk && calleeMessageHashOk;

                log.Trace("Step 6: {0}", step6Ok ? "PASSED" : "FAILED");


                PassedArray[Index] = step1Ok && step2Ok && step3Ok && step4Ok && step5Ok && step6Ok;
                log.Trace("PassedArray[{0}] = {1}", Index, PassedArray[Index]);

                res = true;
            }
            catch (Exception e)
            {
                log.Error("Exception occurred: {0}", e.ToString());
            }
            clientCallee.Dispose();
            clientCalleeAppService.Dispose();
            clientCaller.Dispose();
            clientCallerAppService.Dispose();

            log.Trace("(-):{0}", res);
            return(res);
        }
예제 #13
0
        /// <summary>
        /// Implementation of the test itself.
        /// </summary>
        /// <returns>true if the test passes, false otherwise.</returns>
        public override async Task <bool> RunAsync()
        {
            IPAddress NodeIp            = (IPAddress)ArgumentValues["Node IP"];
            int       ClNonCustomerPort = (int)ArgumentValues["clNonCustomer Port"];
            int       ClCustomerPort    = (int)ArgumentValues["clCustomer Port"];

            log.Trace("(NodeIp:'{0}',ClNonCustomerPort:{1},ClCustomerPort:{2})", NodeIp, ClNonCustomerPort, ClCustomerPort);

            bool res = false;

            Passed = false;

            ProtocolClient client1 = new ProtocolClient();
            ProtocolClient client2 = new ProtocolClient(0, new byte[] { 1, 0, 0 }, client1.GetIdentityKeys());

            try
            {
                MessageBuilder mb1 = client1.MessageBuilder;

                // Step 1
                await client1.ConnectAsync(NodeIp, ClNonCustomerPort, true);

                bool establishHomeNodeOk = await client1.EstablishHomeNodeAsync();

                // Step 1 Acceptance
                bool step1Ok = establishHomeNodeOk;
                client1.CloseConnection();


                // Step 2
                await client1.ConnectAsync(NodeIp, ClCustomerPort, true);

                bool checkInOk = await client1.CheckInAsync();

                // Step 2 Acceptance
                bool step2Ok = checkInOk;


                // Step 3
                await client2.ConnectAsync(NodeIp, ClCustomerPort, true);

                checkInOk = await client2.CheckInAsync();

                // Step 3 Acceptance
                bool step3Ok = checkInOk;


                // Step 4
                byte[]  payload        = Encoding.UTF8.GetBytes("test");
                Message requestMessage = mb1.CreatePingRequest(payload);
                bool    disconnectedOk = false;

                // We should be disconnected by now, so sending or receiving should throw.
                try
                {
                    await client1.SendMessageAsync(requestMessage);

                    await client1.ReceiveMessageAsync();
                }
                catch
                {
                    log.Trace("Expected exception occurred.");
                    disconnectedOk = true;
                }

                // Step 4 Acceptance
                bool step4Ok = disconnectedOk;


                Passed = step1Ok && step2Ok && step3Ok && step4Ok;

                res = true;
            }
            catch (Exception e)
            {
                log.Error("Exception occurred: {0}", e.ToString());
            }
            client1.Dispose();
            client2.Dispose();

            log.Trace("(-):{0}", res);
            return(res);
        }
예제 #14
0
        /// <summary>
        /// Implementation of the test itself.
        /// </summary>
        /// <returns>true if the test passes, false otherwise.</returns>
        public override async Task <bool> RunAsync()
        {
            IPAddress NodeIp      = (IPAddress)ArgumentValues["Node IP"];
            int       PrimaryPort = (int)ArgumentValues["primary Port"];

            log.Trace("(NodeIp:'{0}',PrimaryPort:{1})", NodeIp, PrimaryPort);

            bool res = false;

            Passed = false;

            ProtocolClient clientCallee           = new ProtocolClient();
            ProtocolClient clientCalleeAppService = new ProtocolClient(0, new byte[] { 1, 0, 0 }, clientCallee.GetIdentityKeys());

            ProtocolClient clientCaller           = new ProtocolClient();
            ProtocolClient clientCallerAppService = new ProtocolClient(0, new byte[] { 1, 0, 0 }, clientCaller.GetIdentityKeys());

            try
            {
                MessageBuilder mbCallee           = clientCallee.MessageBuilder;
                MessageBuilder mbCalleeAppService = clientCalleeAppService.MessageBuilder;

                MessageBuilder mbCaller           = clientCaller.MessageBuilder;
                MessageBuilder mbCallerAppService = clientCallerAppService.MessageBuilder;

                // Step 1
                log.Trace("Step 1");
                // Get port list.
                byte[] pubKeyCallee     = clientCallee.GetIdentityKeys().PublicKey;
                byte[] identityIdCallee = clientCallee.GetIdentityId();

                byte[] pubKeyCaller     = clientCaller.GetIdentityKeys().PublicKey;
                byte[] identityIdCaller = clientCaller.GetIdentityId();


                await clientCallee.ConnectAsync(NodeIp, PrimaryPort, false);

                Dictionary <ServerRoleType, uint> rolePorts = new Dictionary <ServerRoleType, uint>();
                bool listPortsOk = await clientCallee.ListNodePorts(rolePorts);

                clientCallee.CloseConnection();


                // Establish home node for identity 1.
                await clientCallee.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool establishHomeNodeOk = await clientCallee.EstablishHomeNodeAsync();

                clientCallee.CloseConnection();


                // Check-in and initialize the profile of identity 1.

                await clientCallee.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClCustomer], true);

                bool checkInOk = await clientCallee.CheckInAsync();

                bool initializeProfileOk = await clientCallee.InitializeProfileAsync("Test Identity", null, 0x12345678, null);


                // Add application service to the current session.
                string serviceName     = "Test Service";
                bool   addAppServiceOk = await clientCallee.AddApplicationServicesAsync(new List <string>() { serviceName });


                // Step 1 Acceptance
                bool step1Ok = listPortsOk && establishHomeNodeOk && checkInOk && initializeProfileOk && addAppServiceOk;

                log.Trace("Step 1: {0}", step1Ok ? "PASSED" : "FAILED");



                // Step 2
                log.Trace("Step 2");
                await clientCaller.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool verifyIdentityOk = await clientCaller.VerifyIdentityAsync();

                Message requestMessage = mbCaller.CreateCallIdentityApplicationServiceRequest(identityIdCallee, serviceName);
                await clientCaller.SendMessageAsync(requestMessage);


                // Step 2 Acceptance
                bool step2Ok = verifyIdentityOk;

                log.Trace("Step 2: {0}", step2Ok ? "PASSED" : "FAILED");



                // Step 3
                log.Trace("Step 3");
                Message nodeRequestMessage = await clientCallee.ReceiveMessageAsync();

                byte[] receivedPubKey = nodeRequestMessage.Request.ConversationRequest.IncomingCallNotification.CallerPublicKey.ToByteArray();
                bool   pubKeyOk       = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, pubKeyCaller) == 0;
                bool   serviceNameOk  = nodeRequestMessage.Request.ConversationRequest.IncomingCallNotification.ServiceName == serviceName;

                bool incomingCallNotificationOk = pubKeyOk && serviceNameOk;

                byte[] calleeToken = nodeRequestMessage.Request.ConversationRequest.IncomingCallNotification.CalleeToken.ToByteArray();

                Message nodeResponseMessage = mbCallee.CreateIncomingCallNotificationResponse(nodeRequestMessage);
                await clientCallee.SendMessageAsync(nodeResponseMessage);


                // Connect to clAppService and send initialization message.
                await clientCalleeAppService.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClAppService], true);

                Message requestMessageAppServiceCallee = mbCalleeAppService.CreateApplicationServiceSendMessageRequest(calleeToken, null);
                await clientCalleeAppService.SendMessageAsync(requestMessageAppServiceCallee);


                // Step 3 Acceptance
                bool step3Ok = incomingCallNotificationOk;

                log.Trace("Step 3: {0}", step3Ok ? "PASSED" : "FAILED");



                // Step 4
                log.Trace("Step 4");
                Message responseMessage = await clientCaller.ReceiveMessageAsync();

                bool   idOk        = responseMessage.Id == requestMessage.Id;
                bool   statusOk    = responseMessage.Response.Status == Status.Ok;
                byte[] callerToken = responseMessage.Response.ConversationResponse.CallIdentityApplicationService.CallerToken.ToByteArray();

                bool callIdentityOk = idOk && statusOk;

                // Connect to clAppService and send initialization message.
                await clientCallerAppService.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClAppService], true);

                Message requestMessageAppServiceCaller = mbCallerAppService.CreateApplicationServiceSendMessageRequest(callerToken, null);
                await clientCallerAppService.SendMessageAsync(requestMessageAppServiceCaller);

                Message responseMessageAppServiceCaller = await clientCallerAppService.ReceiveMessageAsync();

                idOk     = responseMessageAppServiceCaller.Id == requestMessageAppServiceCaller.Id;
                statusOk = responseMessageAppServiceCaller.Response.Status == Status.Ok;

                bool initAppServiceMessageOk = idOk && statusOk;

                clientCaller.CloseConnection();


                // Step 4 Acceptance
                bool step4Ok = callIdentityOk && initAppServiceMessageOk;

                log.Trace("Step 4: {0}", step4Ok ? "PASSED" : "FAILED");



                // Step 5
                log.Trace("Step 5");
                Message responseMessageAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync();

                idOk     = responseMessageAppServiceCallee.Id == requestMessageAppServiceCallee.Id;
                statusOk = responseMessageAppServiceCallee.Response.Status == Status.Ok;

                bool appServiceSendOk = idOk && statusOk;


                // Step 5 Acceptance
                bool step5Ok = appServiceSendOk;

                log.Trace("Step 5: {0}", step5Ok ? "PASSED" : "FAILED");



                // Step 6
                log.Trace("Step 6");

                bool error             = false;
                int  messagesDelivered = 0;
                int  messagesSent      = 0;
                bool disconnectedOk    = false;
                for (int i = 0; i < 20; i++)
                {
                    try
                    {
                        // Caller sends message.
                        string callerMessage = string.Format("Message #{0} to callee.", i + 1);
                        byte[] messageBytes  = Encoding.UTF8.GetBytes(callerMessage);
                        requestMessageAppServiceCaller = mbCallerAppService.CreateApplicationServiceSendMessageRequest(callerToken, messageBytes);
                        await clientCallerAppService.SendMessageAsync(requestMessageAppServiceCaller);

                        messagesSent++;


                        // Callee receives message.
                        Message nodeRequestAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync();

                        byte[] receivedVersion = nodeRequestAppServiceCallee.Request.SingleRequest.Version.ToByteArray();
                        bool   versionOk       = StructuralComparisons.StructuralComparer.Compare(receivedVersion, new byte[] { 1, 0, 0 }) == 0;

                        bool typeOk = (nodeRequestAppServiceCallee.MessageTypeCase == Message.MessageTypeOneofCase.Request) &&
                                      (nodeRequestAppServiceCallee.Request.ConversationTypeCase == Request.ConversationTypeOneofCase.SingleRequest) &&
                                      (nodeRequestAppServiceCallee.Request.SingleRequest.RequestTypeCase == SingleRequest.RequestTypeOneofCase.ApplicationServiceReceiveMessageNotification);

                        string receivedMessage = Encoding.UTF8.GetString(nodeRequestAppServiceCallee.Request.SingleRequest.ApplicationServiceReceiveMessageNotification.Message.ToByteArray());
                        bool   messageOk       = receivedMessage == callerMessage;

                        bool receiveMessageOk = versionOk && typeOk && messageOk;

                        if (receiveMessageOk)
                        {
                            messagesDelivered++;
                            log.Trace("Delivery of message #{0} succeeded.", i + 1);
                        }
                        else
                        {
                            log.Trace("Delivery of message #{0} failed.", i + 1);
                            error = true;
                            break;
                        }

                        await Task.Delay(10 * 1000);
                    }
                    catch
                    {
                        log.Trace("Expected exception occurred.");
                        disconnectedOk = true;
                        break;
                    }
                }



                // Step 6 Acceptance
                bool step6Ok = !error && disconnectedOk && (messagesDelivered < 20);

                log.Trace("Step 6: {0}", step6Ok ? "PASSED" : "FAILED");


                Passed = step1Ok && step2Ok && step3Ok && step4Ok && step5Ok && step6Ok;

                res = true;
            }
            catch (Exception e)
            {
                log.Error("Exception occurred: {0}", e.ToString());
            }
            clientCallee.Dispose();
            clientCalleeAppService.Dispose();
            clientCaller.Dispose();
            clientCallerAppService.Dispose();

            log.Trace("(-):{0}", res);
            return(res);
        }
예제 #15
0
        /// <summary>
        /// Implementation of the test itself.
        /// </summary>
        /// <returns>true if the test passes, false otherwise.</returns>
        public override async Task <bool> RunAsync()
        {
            IPAddress NodeIp      = (IPAddress)ArgumentValues["Node IP"];
            int       PrimaryPort = (int)ArgumentValues["primary Port"];

            log.Trace("(NodeIp:'{0}',PrimaryPort:{1})", NodeIp, PrimaryPort);

            bool res = false;

            Passed = false;

            ProtocolClient clientCallee           = new ProtocolClient();
            ProtocolClient clientCalleeAppService = new ProtocolClient(0, new byte[] { 1, 0, 0 }, clientCallee.GetIdentityKeys());

            ProtocolClient clientCaller           = new ProtocolClient();
            ProtocolClient clientCallerAppService = new ProtocolClient(0, new byte[] { 1, 0, 0 }, clientCaller.GetIdentityKeys());

            try
            {
                MessageBuilder mbCallee           = clientCallee.MessageBuilder;
                MessageBuilder mbCalleeAppService = clientCalleeAppService.MessageBuilder;

                MessageBuilder mbCaller           = clientCaller.MessageBuilder;
                MessageBuilder mbCallerAppService = clientCallerAppService.MessageBuilder;

                // Step 1
                log.Trace("Step 1");
                // Get port list.
                byte[] pubKeyCallee     = clientCallee.GetIdentityKeys().PublicKey;
                byte[] identityIdCallee = clientCallee.GetIdentityId();

                byte[] pubKeyCaller     = clientCaller.GetIdentityKeys().PublicKey;
                byte[] identityIdCaller = clientCaller.GetIdentityId();


                await clientCallee.ConnectAsync(NodeIp, PrimaryPort, false);

                Dictionary <ServerRoleType, uint> rolePorts = new Dictionary <ServerRoleType, uint>();
                bool listPortsOk = await clientCallee.ListNodePorts(rolePorts);

                clientCallee.CloseConnection();


                // Establish home node for identity 1.
                await clientCallee.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool establishHomeNodeOk = await clientCallee.EstablishHomeNodeAsync();

                clientCallee.CloseConnection();


                // Check-in and initialize the profile of identity 1.

                await clientCallee.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClCustomer], true);

                bool checkInOk = await clientCallee.CheckInAsync();

                bool initializeProfileOk = await clientCallee.InitializeProfileAsync("Test Identity", null, 0x12345678, null);


                // Add application service to the current session.
                string serviceName     = "Test Service";
                bool   addAppServiceOk = await clientCallee.AddApplicationServicesAsync(new List <string>() { serviceName });


                // Step 1 Acceptance
                bool step1Ok = listPortsOk && establishHomeNodeOk && checkInOk && initializeProfileOk && addAppServiceOk;

                log.Trace("Step 1: {0}", step1Ok ? "PASSED" : "FAILED");



                // Step 2
                log.Trace("Step 2");
                await clientCaller.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool verifyIdentityOk = await clientCaller.VerifyIdentityAsync();

                Message requestMessage = mbCaller.CreateCallIdentityApplicationServiceRequest(identityIdCallee, serviceName);
                await clientCaller.SendMessageAsync(requestMessage);


                // Step 2 Acceptance
                bool step2Ok = verifyIdentityOk;

                log.Trace("Step 2: {0}", step2Ok ? "PASSED" : "FAILED");



                // Step 3
                log.Trace("Step 3");
                Message nodeRequestMessage = await clientCallee.ReceiveMessageAsync();

                byte[] receivedPubKey = nodeRequestMessage.Request.ConversationRequest.IncomingCallNotification.CallerPublicKey.ToByteArray();
                bool   pubKeyOk       = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, pubKeyCaller) == 0;
                bool   serviceNameOk  = nodeRequestMessage.Request.ConversationRequest.IncomingCallNotification.ServiceName == serviceName;

                bool incomingCallNotificationOk = pubKeyOk && serviceNameOk;

                byte[] calleeToken = nodeRequestMessage.Request.ConversationRequest.IncomingCallNotification.CalleeToken.ToByteArray();

                Message nodeResponseMessage = mbCallee.CreateIncomingCallNotificationResponse(nodeRequestMessage);
                await clientCallee.SendMessageAsync(nodeResponseMessage);


                // Connect to clAppService and send initialization message.
                await clientCalleeAppService.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClAppService], true);

                Message requestMessageAppServiceCallee = mbCalleeAppService.CreateApplicationServiceSendMessageRequest(calleeToken, null);
                await clientCalleeAppService.SendMessageAsync(requestMessageAppServiceCallee);


                // Step 3 Acceptance
                bool step3Ok = incomingCallNotificationOk;

                log.Trace("Step 3: {0}", step3Ok ? "PASSED" : "FAILED");


                // Step 4
                log.Trace("Step 4");
                Message responseMessage = await clientCaller.ReceiveMessageAsync();

                bool   idOk        = responseMessage.Id == requestMessage.Id;
                bool   statusOk    = responseMessage.Response.Status == Status.Ok;
                byte[] callerToken = responseMessage.Response.ConversationResponse.CallIdentityApplicationService.CallerToken.ToByteArray();

                bool callIdentityOk = idOk && statusOk;

                // Connect to clAppService and send initialization message.
                await clientCallerAppService.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClAppService], true);

                Message requestMessageAppServiceCaller = mbCallerAppService.CreateApplicationServiceSendMessageRequest(callerToken, null);
                await clientCallerAppService.SendMessageAsync(requestMessageAppServiceCaller);

                Message responseMessageAppServiceCaller = await clientCallerAppService.ReceiveMessageAsync();

                idOk     = responseMessageAppServiceCaller.Id == requestMessageAppServiceCaller.Id;
                statusOk = responseMessageAppServiceCaller.Response.Status == Status.Ok;

                bool initAppServiceMessageOk = idOk && statusOk;

                // And close connection to clNonCustomer port.
                clientCaller.CloseConnection();


                // Step 4 Acceptance
                bool step4Ok = callIdentityOk && initAppServiceMessageOk;

                log.Trace("Step 4: {0}", step4Ok ? "PASSED" : "FAILED");



                // Step 5
                log.Trace("Step 5");
                Message responseMessageAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync();

                idOk     = responseMessageAppServiceCallee.Id == requestMessageAppServiceCallee.Id;
                statusOk = responseMessageAppServiceCallee.Response.Status == Status.Ok;

                bool typeOk = (responseMessageAppServiceCallee.MessageTypeCase == Message.MessageTypeOneofCase.Response) &&
                              (responseMessageAppServiceCallee.Response.ConversationTypeCase == Response.ConversationTypeOneofCase.SingleResponse) &&
                              (responseMessageAppServiceCallee.Response.SingleResponse.ResponseTypeCase == SingleResponse.ResponseTypeOneofCase.ApplicationServiceSendMessage);

                bool appServiceSendOk = idOk && statusOk && typeOk;

                // Step 5 Acceptance
                bool step5Ok = appServiceSendOk;

                log.Trace("Step 5: {0}", step5Ok ? "PASSED" : "FAILED");



                // Step 6
                log.Trace("Step 6");
                string callerMessage1 = "Message #1 to callee.";
                byte[] messageBytes   = Encoding.UTF8.GetBytes(callerMessage1);
                requestMessageAppServiceCaller = mbCallerAppService.CreateApplicationServiceSendMessageRequest(callerToken, messageBytes);
                uint callerMessage1Id = requestMessageAppServiceCaller.Id;
                await clientCallerAppService.SendMessageAsync(requestMessageAppServiceCaller);


                // Step 6 Acceptance
                bool step6Ok = true;

                log.Trace("Step 6: {0}", step6Ok ? "PASSED" : "FAILED");


                // Step 7
                log.Trace("Step 7");
                // Receive message #1.
                Message nodeRequestAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync();

                byte[] receivedVersion = nodeRequestAppServiceCallee.Request.SingleRequest.Version.ToByteArray();
                bool   versionOk       = StructuralComparisons.StructuralComparer.Compare(receivedVersion, new byte[] { 1, 0, 0 }) == 0;

                typeOk = (nodeRequestAppServiceCallee.MessageTypeCase == Message.MessageTypeOneofCase.Request) &&
                         (nodeRequestAppServiceCallee.Request.ConversationTypeCase == Request.ConversationTypeOneofCase.SingleRequest) &&
                         (nodeRequestAppServiceCallee.Request.SingleRequest.RequestTypeCase == SingleRequest.RequestTypeOneofCase.ApplicationServiceReceiveMessageNotification);

                string receivedMessage = Encoding.UTF8.GetString(nodeRequestAppServiceCallee.Request.SingleRequest.ApplicationServiceReceiveMessageNotification.Message.ToByteArray());
                bool   messageOk       = receivedMessage == callerMessage1;

                bool receiveMessageOk = versionOk && typeOk && messageOk;


                // ACK message #1.
                Message nodeResponseAppServiceCallee = mbCalleeAppService.CreateApplicationServiceReceiveMessageNotificationResponse(nodeRequestAppServiceCallee);
                await clientCalleeAppService.SendMessageAsync(nodeResponseAppServiceCallee);


                // Send our message #1.
                string calleeMessage1 = "Message #1 to CALLER.";
                messageBytes = Encoding.UTF8.GetBytes(calleeMessage1);
                requestMessageAppServiceCallee = mbCalleeAppService.CreateApplicationServiceSendMessageRequest(calleeToken, messageBytes);
                uint calleeMessage1Id = requestMessageAppServiceCallee.Id;
                await clientCalleeAppService.SendMessageAsync(requestMessageAppServiceCallee);



                // Step 7 Acceptance
                bool step7Ok = receiveMessageOk;

                log.Trace("Step 7: {0}", step7Ok ? "PASSED" : "FAILED");


                // Step 8
                log.Trace("Step 8");
                // Receive ACK message #1.
                responseMessageAppServiceCaller = await clientCallerAppService.ReceiveMessageAsync();

                idOk            = responseMessageAppServiceCaller.Id == callerMessage1Id;
                statusOk        = responseMessageAppServiceCaller.Response.Status == Status.Ok;
                receivedVersion = responseMessageAppServiceCaller.Response.SingleResponse.Version.ToByteArray();
                versionOk       = StructuralComparisons.StructuralComparer.Compare(receivedVersion, new byte[] { 1, 0, 0 }) == 0;

                bool receiveAckOk = idOk && statusOk && versionOk;


                // Receive message #1 from callee.
                Message nodeRequestAppServiceCaller = await clientCallerAppService.ReceiveMessageAsync();

                receivedVersion = nodeRequestAppServiceCaller.Request.SingleRequest.Version.ToByteArray();
                versionOk       = StructuralComparisons.StructuralComparer.Compare(receivedVersion, new byte[] { 1, 0, 0 }) == 0;

                typeOk = (nodeRequestAppServiceCaller.MessageTypeCase == Message.MessageTypeOneofCase.Request) &&
                         (nodeRequestAppServiceCaller.Request.ConversationTypeCase == Request.ConversationTypeOneofCase.SingleRequest) &&
                         (nodeRequestAppServiceCaller.Request.SingleRequest.RequestTypeCase == SingleRequest.RequestTypeOneofCase.ApplicationServiceReceiveMessageNotification);

                receivedMessage = Encoding.UTF8.GetString(nodeRequestAppServiceCaller.Request.SingleRequest.ApplicationServiceReceiveMessageNotification.Message.ToByteArray());
                messageOk       = receivedMessage == calleeMessage1;

                receiveMessageOk = versionOk && typeOk && messageOk;


                // ACK message #1 from callee.
                Message nodeResponseAppServiceCaller = mbCallerAppService.CreateApplicationServiceReceiveMessageNotificationResponse(nodeRequestAppServiceCaller);
                await clientCallerAppService.SendMessageAsync(nodeResponseAppServiceCaller);


                // Step 8 Acceptance
                bool step8Ok = receiveAckOk && receiveMessageOk;

                log.Trace("Step 8: {0}", step8Ok ? "PASSED" : "FAILED");


                // Step 9
                log.Trace("Step 9");
                // Receive ACK message #1.
                responseMessageAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync();

                idOk            = responseMessageAppServiceCallee.Id == calleeMessage1Id;
                statusOk        = responseMessageAppServiceCallee.Response.Status == Status.Ok;
                receivedVersion = responseMessageAppServiceCallee.Response.SingleResponse.Version.ToByteArray();
                versionOk       = StructuralComparisons.StructuralComparer.Compare(receivedVersion, new byte[] { 1, 0, 0 }) == 0;

                receiveAckOk = idOk && statusOk && versionOk;

                log.Trace("Going to wait for 3 minutes...");
                await Task.Delay(180 * 1000);

                log.Trace("Waiting done.");


                // Step 9 Acceptance
                bool step9Ok = receiveAckOk;

                log.Trace("Step 9: {0}", step9Ok ? "PASSED" : "FAILED");


                // Step 10
                string callerMessage2 = "Message #1 to callee.";
                messageBytes = Encoding.UTF8.GetBytes(callerMessage2);
                requestMessageAppServiceCaller = mbCallerAppService.CreateApplicationServiceSendMessageRequest(callerToken, messageBytes);

                // We should be disconnected now, send or receive should throw.
                bool disconnectedOk = false;
                try
                {
                    await clientCallerAppService.SendMessageAsync(requestMessageAppServiceCaller);

                    await clientCallerAppService.ReceiveMessageAsync();
                }
                catch
                {
                    log.Trace("Expected exception occurred.");
                    disconnectedOk = true;
                }

                // Step 10 Acceptance
                bool step10Ok = disconnectedOk;

                log.Trace("Step 10: {0}", step10Ok ? "PASSED" : "FAILED");



                // Step 11
                string calleeMessage2 = "Message #1 to CALLER.";
                messageBytes = Encoding.UTF8.GetBytes(calleeMessage2);
                requestMessageAppServiceCallee = mbCalleeAppService.CreateApplicationServiceSendMessageRequest(calleeToken, messageBytes);

                // We should be disconnected now, send or receive should throw.
                disconnectedOk = false;
                try
                {
                    await clientCalleeAppService.SendMessageAsync(requestMessageAppServiceCallee);

                    await clientCalleeAppService.ReceiveMessageAsync();
                }
                catch
                {
                    log.Trace("Expected exception occurred.");
                    disconnectedOk = true;
                }

                // Step 11 Acceptance
                bool step11Ok = disconnectedOk;

                log.Trace("Step 11: {0}", step11Ok ? "PASSED" : "FAILED");


                Passed = step1Ok && step2Ok && step3Ok && step4Ok && step5Ok && step6Ok && step7Ok && step8Ok && step9Ok && step10Ok && step11Ok;

                res = true;
            }
            catch (Exception e)
            {
                log.Error("Exception occurred: {0}", e.ToString());
            }
            clientCallee.Dispose();
            clientCalleeAppService.Dispose();
            clientCaller.Dispose();
            clientCallerAppService.Dispose();

            log.Trace("(-):{0}", res);
            return(res);
        }
예제 #16
0
        /// <summary>
        /// Implementation of the test itself.
        /// </summary>
        /// <returns>true if the test passes, false otherwise.</returns>
        public override async Task <bool> RunAsync()
        {
            IPAddress NodeIp            = (IPAddress)ArgumentValues["Node IP"];
            int       ClNonCustomerPort = (int)ArgumentValues["clNonCustomer Port"];
            int       ClCustomerPort    = (int)ArgumentValues["clCustomer Port"];

            log.Trace("(NodeIp:'{0}',ClNonCustomerPort:{1},ClCustomerPort:{2})", NodeIp, ClNonCustomerPort, ClCustomerPort);

            bool res = false;

            Passed = false;

            ProtocolClient client = new ProtocolClient();

            try
            {
                MessageBuilder mb             = client.MessageBuilder;
                byte[]         testIdentityId = client.GetIdentityId();

                // Step 1
                await client.ConnectAsync(NodeIp, ClNonCustomerPort, true);

                bool establishHomeNodeOk = await client.EstablishHomeNodeAsync();

                // Step 1 Acceptance
                bool step1Ok = establishHomeNodeOk;
                client.CloseConnection();


                // Step 2
                await client.ConnectAsync(NodeIp, ClCustomerPort, true);

                bool checkInOk = await client.CheckInAsync();

                byte[]  newNodeId      = Crypto.Sha1(Encoding.UTF8.GetBytes("test"));
                Message requestMessage = mb.CreateCancelHomeNodeAgreementRequest(newNodeId);
                await client.SendMessageAsync(requestMessage);

                Message responseMessage = await client.ReceiveMessageAsync();

                bool idOk     = responseMessage.Id == requestMessage.Id;
                bool statusOk = responseMessage.Response.Status == Status.Ok;

                bool cancelAgreementOk = idOk && statusOk;


                requestMessage = mb.CreateGetIdentityInformationRequest(testIdentityId);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;
                bool   isHostedOk = responseMessage.Response.SingleResponse.GetIdentityInformation.IsHosted == false;
                bool   isTargetHomeNodeKnownOk = responseMessage.Response.SingleResponse.GetIdentityInformation.IsTargetHomeNodeKnown;
                byte[] receivedHomeNodeId      = responseMessage.Response.SingleResponse.GetIdentityInformation.TargetHomeNodeNetworkId.ToByteArray();
                bool   targetHomeNodeIdOk      = StructuralComparisons.StructuralComparer.Compare(receivedHomeNodeId, newNodeId) == 0;

                bool getIdentityInfoOk = idOk && statusOk && isHostedOk && isTargetHomeNodeKnownOk && targetHomeNodeIdOk;

                // Step 2 Acceptance
                bool step2Ok = checkInOk && cancelAgreementOk && getIdentityInfoOk;


                Passed = step1Ok && step2Ok;

                res = true;
            }
            catch (Exception e)
            {
                log.Error("Exception occurred: {0}", e.ToString());
            }
            client.Dispose();

            log.Trace("(-):{0}", res);
            return(res);
        }
예제 #17
0
        /// <summary>
        /// Implementation of the test itself.
        /// </summary>
        /// <returns>true if the test passes, false otherwise.</returns>
        public override async Task <bool> RunAsync()
        {
            IPAddress NodeIp            = (IPAddress)ArgumentValues["Node IP"];
            int       ClNonCustomerPort = (int)ArgumentValues["clNonCustomer Port"];
            int       ClCustomerPort    = (int)ArgumentValues["clCustomer Port"];

            log.Trace("(NodeIp:'{0}',ClNonCustomerPort:{1},ClCustomerPort:{2})", NodeIp, ClNonCustomerPort, ClCustomerPort);

            bool res = false;

            Passed = false;

            ProtocolClient client = new ProtocolClient();

            try
            {
                MessageBuilder mb             = client.MessageBuilder;
                byte[]         testPubKey     = client.GetIdentityKeys().PublicKey;
                byte[]         testIdentityId = client.GetIdentityId();

                // Step 1
                await client.ConnectAsync(NodeIp, ClNonCustomerPort, true);

                bool establishHomeNodeOk = await client.EstablishHomeNodeAsync();

                // Step 1 Acceptance
                bool step1Ok = establishHomeNodeOk;
                client.CloseConnection();


                // Step 2
                await client.ConnectAsync(NodeIp, ClCustomerPort, true);

                bool checkInOk = await client.CheckInAsync();

                Message requestMessage = mb.CreateUpdateProfileRequest(null, "Test Identity", null, 0x12345678, null);
                await client.SendMessageAsync(requestMessage);

                Message responseMessage = await client.ReceiveMessageAsync();

                bool idOk      = responseMessage.Id == requestMessage.Id;
                bool statusOk  = responseMessage.Response.Status == Status.ErrorInvalidValue;
                bool detailsOk = responseMessage.Response.Details == "setVersion";

                bool updateProfileOk1 = idOk && statusOk && detailsOk;


                requestMessage = mb.CreateUpdateProfileRequest(new byte[] { 1, 0, 0 }, null, null, 0x12345678, null);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk      = responseMessage.Id == requestMessage.Id;
                statusOk  = responseMessage.Response.Status == Status.ErrorInvalidValue;
                detailsOk = responseMessage.Response.Details == "setName";

                bool updateProfileOk2 = idOk && statusOk && detailsOk;


                requestMessage = mb.CreateUpdateProfileRequest(new byte[] { 1, 0, 0 }, "Test Identity", null, null, null);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk      = responseMessage.Id == requestMessage.Id;
                statusOk  = responseMessage.Response.Status == Status.ErrorInvalidValue;
                detailsOk = responseMessage.Response.Details == "setLocation";

                bool updateProfileOk3 = idOk && statusOk && detailsOk;


                requestMessage = mb.CreateUpdateProfileRequest(new byte[] { 0, 0, 0 }, "Test Identity", null, 0x12345678, null);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk      = responseMessage.Id == requestMessage.Id;
                statusOk  = responseMessage.Response.Status == Status.ErrorInvalidValue;
                detailsOk = responseMessage.Response.Details == "version";

                bool updateProfileOk4 = idOk && statusOk && detailsOk;


                requestMessage = mb.CreateUpdateProfileRequest(new byte[] { 255, 0, 0 }, "Test Identity", null, 0x12345678, null);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk      = responseMessage.Id == requestMessage.Id;
                statusOk  = responseMessage.Response.Status == Status.ErrorInvalidValue;
                detailsOk = responseMessage.Response.Details == "version";

                bool updateProfileOk5 = idOk && statusOk && detailsOk;


                requestMessage = mb.CreateUpdateProfileRequest(new byte[] { 1, 0, 0 }, "", null, 0x12345678, null);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk      = responseMessage.Id == requestMessage.Id;
                statusOk  = responseMessage.Response.Status == Status.ErrorInvalidValue;
                detailsOk = responseMessage.Response.Details == "name";

                bool updateProfileOk6 = idOk && statusOk && detailsOk;

                string name = new string('a', 100);
                requestMessage = mb.CreateUpdateProfileRequest(new byte[] { 1, 0, 0 }, name, null, 0x12345678, null);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk      = responseMessage.Id == requestMessage.Id;
                statusOk  = responseMessage.Response.Status == Status.ErrorInvalidValue;
                detailsOk = responseMessage.Response.Details == "name";

                bool updateProfileOk7 = idOk && statusOk && detailsOk;


                name           = new string('ɐ', 50);
                requestMessage = mb.CreateUpdateProfileRequest(new byte[] { 1, 0, 0 }, name, null, 0x12345678, null);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk      = responseMessage.Id == requestMessage.Id;
                statusOk  = responseMessage.Response.Status == Status.ErrorInvalidValue;
                detailsOk = responseMessage.Response.Details == "name";

                bool updateProfileOk8 = idOk && statusOk && detailsOk;


                byte[] imageData = File.ReadAllBytes(string.Format("images{0}HN04007-too-big.jpg", Path.DirectorySeparatorChar));
                requestMessage = mb.CreateUpdateProfileRequest(new byte[] { 1, 0, 0 }, "Test Identity", imageData, 0x12345678, null);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk      = responseMessage.Id == requestMessage.Id;
                statusOk  = responseMessage.Response.Status == Status.ErrorInvalidValue;
                detailsOk = responseMessage.Response.Details == "image";

                bool updateProfileOk9 = idOk && statusOk && detailsOk;


                imageData      = File.ReadAllBytes(string.Format("images{0}HN04007-not-image.jpg", Path.DirectorySeparatorChar));
                requestMessage = mb.CreateUpdateProfileRequest(new byte[] { 1, 0, 0 }, "Test Identity", imageData, 0x12345678, null);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk      = responseMessage.Id == requestMessage.Id;
                statusOk  = responseMessage.Response.Status == Status.ErrorInvalidValue;
                detailsOk = responseMessage.Response.Details == "image";

                bool updateProfileOk10 = idOk && statusOk && detailsOk;


                string extraData = new string('a', 300);
                requestMessage = mb.CreateUpdateProfileRequest(new byte[] { 1, 0, 0 }, "Test Identity", null, 0x12345678, extraData);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk      = responseMessage.Id == requestMessage.Id;
                statusOk  = responseMessage.Response.Status == Status.ErrorInvalidValue;
                detailsOk = responseMessage.Response.Details == "extraData";

                bool updateProfileOk11 = idOk && statusOk && detailsOk;


                extraData      = new string('ɐ', 150);
                requestMessage = mb.CreateUpdateProfileRequest(new byte[] { 1, 0, 0 }, "Test Identity", null, 0x12345678, extraData);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk      = responseMessage.Id == requestMessage.Id;
                statusOk  = responseMessage.Response.Status == Status.ErrorInvalidValue;
                detailsOk = responseMessage.Response.Details == "extraData";

                bool updateProfileOk12 = idOk && statusOk && detailsOk;


                requestMessage = mb.CreateUpdateProfileRequest(new byte[] { 1, 0, 0 }, "Test Identity", null, 0x12345678, null);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;

                bool updateProfileOk13 = idOk && statusOk;


                requestMessage = mb.CreateUpdateProfileRequest(null, null, null, null, null);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk      = responseMessage.Id == requestMessage.Id;
                statusOk  = responseMessage.Response.Status == Status.ErrorInvalidValue;
                detailsOk = responseMessage.Response.Details == "set*";

                bool updateProfileOk14 = idOk && statusOk && detailsOk;


                // Step 2 Acceptance
                bool step2Ok = checkInOk && updateProfileOk1 && updateProfileOk2 && updateProfileOk3 && updateProfileOk4 && updateProfileOk5 && updateProfileOk6 && updateProfileOk7 && updateProfileOk8 &&
                               updateProfileOk9 && updateProfileOk10 && updateProfileOk11 && updateProfileOk12 && updateProfileOk13 && updateProfileOk14;


                Passed = step1Ok && step2Ok;

                res = true;
            }
            catch (Exception e)
            {
                log.Error("Exception occurred: {0}", e.ToString());
            }
            client.Dispose();

            log.Trace("(-):{0}", res);
            return(res);
        }