Example #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 ServerIp          = (IPAddress)ArgumentValues["Server IP"];
            int       ClNonCustomerPort = (int)ArgumentValues["clNonCustomer Port"];
            int       ClCustomerPort    = (int)ArgumentValues["clCustomer Port"];

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

            bool res = false;

            Passed = false;

            ProtocolClient client = new ProtocolClient();

            try
            {
                MessageBuilder mb = client.MessageBuilder;

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

                bool establishHostingOk = await client.EstablishHostingAsync();

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


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

                bool startConversationOk = await client.StartConversationAsync();

                Message requestMessage = mb.CreateUpdateProfileRequest(SemVer.V100, "Test Identity", null, new GpsLocation(0, 0), 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);
        }
Example #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 ServerIp          = (IPAddress)ArgumentValues["Server IP"];
            int       ClNonCustomerPort = (int)ArgumentValues["clNonCustomer Port"];
            int       ClCustomerPort    = ClNonCustomerPort;

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

            bool res = false;

            Passed = false;

            ProtocolClient client = new ProtocolClient();

            try
            {
                MessageBuilder mb = client.MessageBuilder;

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

                bool establishHostingOk = await client.EstablishHostingAsync();

                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 = establishHostingOk && checkInOk;

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

            log.Trace("(-):{0}", res);
            return(res);
        }
Example #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 ServerIp    = (IPAddress)ArgumentValues["Server IP"];
            int       PrimaryPort = (int)ArgumentValues["primary Port"];

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

            bool res = false;

            Passed = false;

            ProtocolClient client = new ProtocolClient();

            try
            {
                MessageBuilder mb = client.MessageBuilder;

                // Step 1
                log.Trace("Step 1");
                // Get port list.
                await client.ConnectAsync(ServerIp, PrimaryPort, false);

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

                client.CloseConnection();

                ProfilePublicKeys = new List <byte[]>();

                bool profileInitializationOk = true;
                for (int i = 0; i < ProfileNames.Count; i++)
                {
                    ProtocolClient profileClient = new ProtocolClient();
                    ProfilePublicKeys.Add(profileClient.GetIdentityKeys().PublicKey);

                    await profileClient.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                    bool establishHostingOk = await profileClient.EstablishHostingAsync(ProfileTypes[i]);

                    profileClient.CloseConnection();


                    await profileClient.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClCustomer], true);

                    bool checkInOk = await profileClient.CheckInAsync();

                    byte[] imageData = ProfileImages[i] != null?File.ReadAllBytes(ProfileImages[i]) : null;

                    bool initializeProfileOk = await profileClient.InitializeProfileAsync(ProfileNames[i], imageData, ProfileLocations[i], ProfileExtraData[i]);

                    profileInitializationOk = establishHostingOk && checkInOk && initializeProfileOk;
                    profileClient.Dispose();

                    if (!profileInitializationOk)
                    {
                        break;
                    }
                }

                ProtocolClient uninitializedProfileClient = new ProtocolClient();
                await uninitializedProfileClient.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool establishHostingUninitializedOk = await uninitializedProfileClient.EstablishHostingAsync("Profile Type B");

                uninitializedProfileClient.CloseConnection();
                uninitializedProfileClient.Dispose();


                bool step1Ok = listPortsOk && profileInitializationOk && establishHostingUninitializedOk;
                log.Trace("Step 1: {0}", step1Ok ? "PASSED" : "FAILED");



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

                bool startConversationOk = await client.StartConversationAsync();

                Message requestMessage = mb.CreateProfileSearchRequest(null, null, null, null, 0, 100, 100);
                await client.SendMessageAsync(requestMessage);

                Message responseMessage = await client.ReceiveMessageAsync();

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


                HashSet <int> numberList = new HashSet <int>()
                {
                    1, 2, 3, 4, 5, 6, 7
                };
                bool totalRecordCountOk       = responseMessage.Response.ConversationResponse.ProfileSearch.TotalRecordCount == numberList.Count;
                bool maxResponseRecordCountOk = responseMessage.Response.ConversationResponse.ProfileSearch.MaxResponseRecordCount == 100;
                bool profilesCountOk          = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count == numberList.Count;

                bool profileListOk = CheckProfileList(numberList, responseMessage.Response.ConversationResponse.ProfileSearch.Profiles);

                // Step 2 Acceptance
                bool step2Ok = startConversationOk && idOk && statusOk && totalRecordCountOk && maxResponseRecordCountOk && profilesCountOk && profileListOk;

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


                // Step 3
                log.Trace("Step 3");
                requestMessage = mb.CreateProfileSearchRequest("*Type B", null, null, null, 0, 100, 100);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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


                numberList = new HashSet <int>()
                {
                    4, 5
                };
                totalRecordCountOk       = responseMessage.Response.ConversationResponse.ProfileSearch.TotalRecordCount == numberList.Count;
                maxResponseRecordCountOk = responseMessage.Response.ConversationResponse.ProfileSearch.MaxResponseRecordCount == 100;
                profilesCountOk          = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count == numberList.Count;

                profileListOk = CheckProfileList(numberList, responseMessage.Response.ConversationResponse.ProfileSearch.Profiles);

                // Step 3 Acceptance
                bool step3Ok = idOk && statusOk && totalRecordCountOk && maxResponseRecordCountOk && profilesCountOk && profileListOk;

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


                // Step 4
                log.Trace("Step 4");
                requestMessage = mb.CreateProfileSearchRequest("Profile Type C", null, null, null, 0, 100, 100);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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


                numberList = new HashSet <int>()
                {
                    6, 7
                };
                totalRecordCountOk       = responseMessage.Response.ConversationResponse.ProfileSearch.TotalRecordCount == numberList.Count;
                maxResponseRecordCountOk = responseMessage.Response.ConversationResponse.ProfileSearch.MaxResponseRecordCount == 100;
                profilesCountOk          = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count == numberList.Count;

                profileListOk = CheckProfileList(numberList, responseMessage.Response.ConversationResponse.ProfileSearch.Profiles);

                // Step 4 Acceptance
                bool step4Ok = idOk && statusOk && totalRecordCountOk && maxResponseRecordCountOk && profilesCountOk && profileListOk;

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


                // Step 5
                log.Trace("Step 5");
                requestMessage = mb.CreateProfileSearchRequest(null, "Mumbai *", null, null, 0, 100, 100);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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


                numberList = new HashSet <int>()
                {
                    2, 6, 7
                };
                totalRecordCountOk       = responseMessage.Response.ConversationResponse.ProfileSearch.TotalRecordCount == numberList.Count;
                maxResponseRecordCountOk = responseMessage.Response.ConversationResponse.ProfileSearch.MaxResponseRecordCount == 100;
                profilesCountOk          = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count == numberList.Count;

                profileListOk = CheckProfileList(numberList, responseMessage.Response.ConversationResponse.ProfileSearch.Profiles);

                // Step 5 Acceptance
                bool step5Ok = idOk && statusOk && totalRecordCountOk && maxResponseRecordCountOk && profilesCountOk && profileListOk;

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


                // Step 6
                log.Trace("Step 6");
                requestMessage = mb.CreateProfileSearchRequest(null, "*ai*", null, null, 0, 100, 100);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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


                numberList = new HashSet <int>()
                {
                    1, 2, 4, 5, 6, 7
                };
                totalRecordCountOk       = responseMessage.Response.ConversationResponse.ProfileSearch.TotalRecordCount == numberList.Count;
                maxResponseRecordCountOk = responseMessage.Response.ConversationResponse.ProfileSearch.MaxResponseRecordCount == 100;
                profilesCountOk          = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count == numberList.Count;

                profileListOk = CheckProfileList(numberList, responseMessage.Response.ConversationResponse.ProfileSearch.Profiles);

                // Step 6 Acceptance
                bool step6Ok = idOk && statusOk && totalRecordCountOk && maxResponseRecordCountOk && profilesCountOk && profileListOk;

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


                // Step 7
                log.Trace("Step 7");
                requestMessage = mb.CreateProfileSearchRequest(null, null, null, new GpsLocation(18.961m, 72.82m), 10, 100, 100);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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


                numberList = new HashSet <int>()
                {
                    6, 7
                };
                totalRecordCountOk       = responseMessage.Response.ConversationResponse.ProfileSearch.TotalRecordCount == numberList.Count;
                maxResponseRecordCountOk = responseMessage.Response.ConversationResponse.ProfileSearch.MaxResponseRecordCount == 100;
                profilesCountOk          = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count == numberList.Count;

                profileListOk = CheckProfileList(numberList, responseMessage.Response.ConversationResponse.ProfileSearch.Profiles);

                // Step 7 Acceptance
                bool step7Ok = idOk && statusOk && totalRecordCountOk && maxResponseRecordCountOk && profilesCountOk && profileListOk;

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


                // Step 8
                log.Trace("Step 8");
                requestMessage = mb.CreateProfileSearchRequest(null, null, null, new GpsLocation(18.961m, 72.82m), 5000, 100, 100);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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


                numberList = new HashSet <int>()
                {
                    2, 6, 7
                };
                totalRecordCountOk       = responseMessage.Response.ConversationResponse.ProfileSearch.TotalRecordCount == numberList.Count;
                maxResponseRecordCountOk = responseMessage.Response.ConversationResponse.ProfileSearch.MaxResponseRecordCount == 100;
                profilesCountOk          = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count == numberList.Count;

                profileListOk = CheckProfileList(numberList, responseMessage.Response.ConversationResponse.ProfileSearch.Profiles);

                // Step 8 Acceptance
                bool step8Ok = idOk && statusOk && totalRecordCountOk && maxResponseRecordCountOk && profilesCountOk && profileListOk;

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


                // Step 9
                log.Trace("Step 9");
                requestMessage = mb.CreateProfileSearchRequest(null, null, null, new GpsLocation(-12.345678m, 12.345678m), 5000, 100, 100);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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


                totalRecordCountOk       = responseMessage.Response.ConversationResponse.ProfileSearch.TotalRecordCount == 0;
                maxResponseRecordCountOk = responseMessage.Response.ConversationResponse.ProfileSearch.MaxResponseRecordCount == 100;
                profilesCountOk          = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count == 0;

                // Step 9 Acceptance
                bool step9Ok = idOk && statusOk && totalRecordCountOk && maxResponseRecordCountOk && profilesCountOk;


                // Step 10
                log.Trace("Step 10");
                requestMessage = mb.CreateProfileSearchRequest(null, null, "no profiles", null, 0, 100, 100);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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


                totalRecordCountOk       = responseMessage.Response.ConversationResponse.ProfileSearch.TotalRecordCount == 0;
                maxResponseRecordCountOk = responseMessage.Response.ConversationResponse.ProfileSearch.MaxResponseRecordCount == 100;
                profilesCountOk          = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count == 0;

                // Step 10 Acceptance
                bool step10Ok = idOk && statusOk && totalRecordCountOk && maxResponseRecordCountOk && profilesCountOk;

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


                // Step 11
                log.Trace("Step 11");
                requestMessage = mb.CreateProfileSearchRequest(null, null, @"(^|;)t=(|[^=]+,)running([;,]|$)", null, 0, 100, 100);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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


                numberList = new HashSet <int>()
                {
                    2, 3, 7
                };
                totalRecordCountOk       = responseMessage.Response.ConversationResponse.ProfileSearch.TotalRecordCount == numberList.Count;
                maxResponseRecordCountOk = responseMessage.Response.ConversationResponse.ProfileSearch.MaxResponseRecordCount == 100;
                profilesCountOk          = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count == numberList.Count;

                profileListOk = CheckProfileList(numberList, responseMessage.Response.ConversationResponse.ProfileSearch.Profiles);

                // Step 11 Acceptance
                bool step11Ok = idOk && statusOk && totalRecordCountOk && maxResponseRecordCountOk && profilesCountOk && profileListOk;

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


                // Step 12
                log.Trace("Step 12");
                requestMessage = mb.CreateProfileSearchRequest(null, null, @".+", null, 0, 2, 100);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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


                totalRecordCountOk       = responseMessage.Response.ConversationResponse.ProfileSearch.TotalRecordCount == 5;
                maxResponseRecordCountOk = responseMessage.Response.ConversationResponse.ProfileSearch.MaxResponseRecordCount == 2;
                profilesCountOk          = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count == 2;

                List <IdentityNetworkProfileInformation> setA = new List <IdentityNetworkProfileInformation>(responseMessage.Response.ConversationResponse.ProfileSearch.Profiles);

                bool firstPartOk = idOk && statusOk && totalRecordCountOk && maxResponseRecordCountOk && profilesCountOk;


                requestMessage = mb.CreateProfileSearchPartRequest(2, 2);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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


                bool recordIndexOk = responseMessage.Response.ConversationResponse.ProfileSearchPart.RecordIndex == 2;
                bool recordCountOk = responseMessage.Response.ConversationResponse.ProfileSearchPart.RecordCount == 2;
                profilesCountOk = responseMessage.Response.ConversationResponse.ProfileSearchPart.Profiles.Count == 2;

                List <IdentityNetworkProfileInformation> setB = new List <IdentityNetworkProfileInformation>(responseMessage.Response.ConversationResponse.ProfileSearchPart.Profiles);

                bool secondPartOk = idOk && statusOk && recordIndexOk && recordCountOk && profilesCountOk;


                requestMessage = mb.CreateProfileSearchPartRequest(4, 1);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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


                recordIndexOk   = responseMessage.Response.ConversationResponse.ProfileSearchPart.RecordIndex == 4;
                recordCountOk   = responseMessage.Response.ConversationResponse.ProfileSearchPart.RecordCount == 1;
                profilesCountOk = responseMessage.Response.ConversationResponse.ProfileSearchPart.Profiles.Count == 1;

                List <IdentityNetworkProfileInformation> setC = new List <IdentityNetworkProfileInformation>(responseMessage.Response.ConversationResponse.ProfileSearchPart.Profiles);

                bool thirdPartOk = idOk && statusOk && recordIndexOk && recordCountOk && profilesCountOk;


                requestMessage = mb.CreateProfileSearchPartRequest(0, 5);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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


                numberList = new HashSet <int>()
                {
                    2, 3, 5, 6, 7
                };
                recordIndexOk   = responseMessage.Response.ConversationResponse.ProfileSearchPart.RecordIndex == 0;
                recordCountOk   = responseMessage.Response.ConversationResponse.ProfileSearchPart.RecordCount == numberList.Count;
                profilesCountOk = responseMessage.Response.ConversationResponse.ProfileSearchPart.Profiles.Count == numberList.Count;

                bool fourthPartOk = idOk && statusOk && recordIndexOk && recordCountOk && profilesCountOk;


                List <IdentityNetworkProfileInformation> setAll = new List <IdentityNetworkProfileInformation>(responseMessage.Response.ConversationResponse.ProfileSearchPart.Profiles);
                bool profileListOk1 = CheckProfileList(numberList, setAll);

                List <IdentityNetworkProfileInformation> setParts = new List <IdentityNetworkProfileInformation>(setA);
                setParts.AddRange(setB);
                setParts.AddRange(setC);
                bool profileListOk2 = CheckProfileList(numberList, setParts);


                // Step 12 Acceptance
                bool step12Ok = firstPartOk && secondPartOk && thirdPartOk && fourthPartOk && profileListOk1 && profileListOk2;

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



                // Step 13
                log.Trace("Step 13");
                requestMessage = mb.CreateProfileSearchRequest(null, null, @"(^|;)t=(|[^=]+,)running([;,]|$)", null, 0, 2, 2, false, false);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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


                totalRecordCountOk       = responseMessage.Response.ConversationResponse.ProfileSearch.TotalRecordCount == 2;
                maxResponseRecordCountOk = responseMessage.Response.ConversationResponse.ProfileSearch.MaxResponseRecordCount == 2;
                profilesCountOk          = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count == 2;

                numberList = new HashSet <int>()
                {
                    2
                };
                profileListOk1 = CheckProfileList(numberList, responseMessage.Response.ConversationResponse.ProfileSearch.Profiles, false, true);

                numberList = new HashSet <int>()
                {
                    3
                };
                profileListOk2 = CheckProfileList(numberList, responseMessage.Response.ConversationResponse.ProfileSearch.Profiles, false, true);

                numberList = new HashSet <int>()
                {
                    7
                };
                bool profileListOk3 = CheckProfileList(numberList, responseMessage.Response.ConversationResponse.ProfileSearch.Profiles, false, true);

                profileListOk = (profileListOk1 && profileListOk2 && !profileListOk3) ||
                                (profileListOk1 && !profileListOk2 && profileListOk3) ||
                                (!profileListOk1 && profileListOk2 && profileListOk3);

                // Step 13 Acceptance
                bool step13Ok = idOk && statusOk && totalRecordCountOk && maxResponseRecordCountOk && profilesCountOk && profileListOk;

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


                // Step 14
                log.Trace("Step 14");
                requestMessage = mb.CreateProfileSearchRequest("profile*", null, null, null, 0, 100, 100);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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


                numberList = new HashSet <int>()
                {
                    1, 2, 3, 4, 5, 6, 7
                };
                totalRecordCountOk       = responseMessage.Response.ConversationResponse.ProfileSearch.TotalRecordCount == numberList.Count;
                maxResponseRecordCountOk = responseMessage.Response.ConversationResponse.ProfileSearch.MaxResponseRecordCount == 100;
                profilesCountOk          = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count == numberList.Count;

                profileListOk = CheckProfileList(numberList, responseMessage.Response.ConversationResponse.ProfileSearch.Profiles);

                // Step 14 Acceptance
                bool step14Ok = idOk && statusOk && totalRecordCountOk && maxResponseRecordCountOk && profilesCountOk && profileListOk;

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


                // Step 15
                log.Trace("Step 15");
                requestMessage = mb.CreateProfileSearchRequest("*file*", null, null, null, 0, 100, 100);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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


                numberList = new HashSet <int>()
                {
                    1, 2, 3, 4, 5, 6, 7
                };
                totalRecordCountOk       = responseMessage.Response.ConversationResponse.ProfileSearch.TotalRecordCount == numberList.Count;
                maxResponseRecordCountOk = responseMessage.Response.ConversationResponse.ProfileSearch.MaxResponseRecordCount == 100;
                profilesCountOk          = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count == numberList.Count;

                profileListOk = CheckProfileList(numberList, responseMessage.Response.ConversationResponse.ProfileSearch.Profiles);

                // Step 15 Acceptance
                bool step15Ok = idOk && statusOk && totalRecordCountOk && maxResponseRecordCountOk && profilesCountOk && profileListOk;

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



                // Step 16
                log.Trace("Step 16");
                requestMessage = mb.CreateProfileSearchRequest("**", null, null, null, 0, 100, 100);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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


                numberList = new HashSet <int>()
                {
                    1, 2, 3, 4, 5, 6, 7
                };
                totalRecordCountOk       = responseMessage.Response.ConversationResponse.ProfileSearch.TotalRecordCount == numberList.Count;
                maxResponseRecordCountOk = responseMessage.Response.ConversationResponse.ProfileSearch.MaxResponseRecordCount == 100;
                profilesCountOk          = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count == numberList.Count;

                profileListOk = CheckProfileList(numberList, responseMessage.Response.ConversationResponse.ProfileSearch.Profiles);

                // Step 16 Acceptance
                bool step16Ok = idOk && statusOk && totalRecordCountOk && maxResponseRecordCountOk && profilesCountOk && profileListOk;

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



                // Step 17
                log.Trace("Step 17");
                requestMessage = mb.CreateProfileSearchRequest("*", null, null, null, 0, 100, 100);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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


                numberList = new HashSet <int>()
                {
                    1, 2, 3, 4, 5, 6, 7
                };
                totalRecordCountOk       = responseMessage.Response.ConversationResponse.ProfileSearch.TotalRecordCount == numberList.Count;
                maxResponseRecordCountOk = responseMessage.Response.ConversationResponse.ProfileSearch.MaxResponseRecordCount == 100;
                profilesCountOk          = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count == numberList.Count;

                profileListOk = CheckProfileList(numberList, responseMessage.Response.ConversationResponse.ProfileSearch.Profiles);

                // Step 17 Acceptance
                bool step17Ok = idOk && statusOk && totalRecordCountOk && maxResponseRecordCountOk && profilesCountOk && profileListOk;

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


                // Step 18
                log.Trace("Step 18");
                requestMessage = mb.CreateProfileSearchRequest(null, "*1", null, null, 0, 100, 100);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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


                numberList = new HashSet <int>()
                {
                    1, 2
                };
                totalRecordCountOk       = responseMessage.Response.ConversationResponse.ProfileSearch.TotalRecordCount == numberList.Count;
                maxResponseRecordCountOk = responseMessage.Response.ConversationResponse.ProfileSearch.MaxResponseRecordCount == 100;
                profilesCountOk          = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count == numberList.Count;

                profileListOk = CheckProfileList(numberList, responseMessage.Response.ConversationResponse.ProfileSearch.Profiles);

                // Step 18 Acceptance
                bool step18Ok = idOk && statusOk && totalRecordCountOk && maxResponseRecordCountOk && profilesCountOk && profileListOk;

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


                // Step 19
                log.Trace("Step 19");
                requestMessage = mb.CreateProfileSearchRequest(null, "Shanghai 1", null, null, 0, 100, 100);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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


                numberList = new HashSet <int>()
                {
                    1
                };
                totalRecordCountOk       = responseMessage.Response.ConversationResponse.ProfileSearch.TotalRecordCount == numberList.Count;
                maxResponseRecordCountOk = responseMessage.Response.ConversationResponse.ProfileSearch.MaxResponseRecordCount == 100;
                profilesCountOk          = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count == numberList.Count;

                profileListOk = CheckProfileList(numberList, responseMessage.Response.ConversationResponse.ProfileSearch.Profiles);

                // Step 19 Acceptance
                bool step19Ok = idOk && statusOk && totalRecordCountOk && maxResponseRecordCountOk && profilesCountOk && profileListOk;

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



                // Step 20
                log.Trace("Step 20");
                requestMessage = mb.CreateProfileSearchRequest(null, "**", null, null, 0, 100, 100);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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


                numberList = new HashSet <int>()
                {
                    1, 2, 3, 4, 5, 6, 7
                };
                totalRecordCountOk       = responseMessage.Response.ConversationResponse.ProfileSearch.TotalRecordCount == numberList.Count;
                maxResponseRecordCountOk = responseMessage.Response.ConversationResponse.ProfileSearch.MaxResponseRecordCount == 100;
                profilesCountOk          = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count == numberList.Count;

                profileListOk = CheckProfileList(numberList, responseMessage.Response.ConversationResponse.ProfileSearch.Profiles);

                // Step 20 Acceptance
                bool step20Ok = idOk && statusOk && totalRecordCountOk && maxResponseRecordCountOk && profilesCountOk && profileListOk;

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



                // Step 21
                log.Trace("Step 21");
                requestMessage = mb.CreateProfileSearchRequest(null, "*", null, null, 0, 100, 100);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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


                numberList = new HashSet <int>()
                {
                    1, 2, 3, 4, 5, 6, 7
                };
                totalRecordCountOk       = responseMessage.Response.ConversationResponse.ProfileSearch.TotalRecordCount == numberList.Count;
                maxResponseRecordCountOk = responseMessage.Response.ConversationResponse.ProfileSearch.MaxResponseRecordCount == 100;
                profilesCountOk          = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count == numberList.Count;

                profileListOk = CheckProfileList(numberList, responseMessage.Response.ConversationResponse.ProfileSearch.Profiles);

                // Step 21 Acceptance
                bool step21Ok = idOk && statusOk && totalRecordCountOk && maxResponseRecordCountOk && profilesCountOk && profileListOk;

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


                // Step 22
                log.Trace("Step 22");
                requestMessage = mb.CreateProfileSearchRequest("*Type A", "*ai*", "water", null, 0, 100, 100);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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


                numberList = new HashSet <int>()
                {
                    2
                };
                totalRecordCountOk       = responseMessage.Response.ConversationResponse.ProfileSearch.TotalRecordCount == numberList.Count;
                maxResponseRecordCountOk = responseMessage.Response.ConversationResponse.ProfileSearch.MaxResponseRecordCount == 100;
                profilesCountOk          = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count == numberList.Count;

                profileListOk = CheckProfileList(numberList, responseMessage.Response.ConversationResponse.ProfileSearch.Profiles);

                // Step 22 Acceptance
                bool step22Ok = idOk && statusOk && totalRecordCountOk && maxResponseRecordCountOk && profilesCountOk && profileListOk;

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



                // Step 23
                log.Trace("Step 23");
                requestMessage = mb.CreateProfileSearchRequest(null, null, @".+", null, 0, 2, 100);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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


                totalRecordCountOk       = responseMessage.Response.ConversationResponse.ProfileSearch.TotalRecordCount == 5;
                maxResponseRecordCountOk = responseMessage.Response.ConversationResponse.ProfileSearch.MaxResponseRecordCount == 2;
                profilesCountOk          = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count == 2;

                firstPartOk = idOk && statusOk && totalRecordCountOk && maxResponseRecordCountOk && profilesCountOk;

                await Task.Delay(15000);

                requestMessage = mb.CreateProfileSearchPartRequest(8, 2);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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

                secondPartOk = idOk && statusOk && detailsOk;


                await Task.Delay(15000);

                requestMessage = mb.CreateProfileSearchPartRequest(4, 5);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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

                thirdPartOk = idOk && statusOk && detailsOk;



                await Task.Delay(22000);

                requestMessage = mb.CreateProfileSearchPartRequest(0, 500);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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

                fourthPartOk = idOk && statusOk && detailsOk;



                requestMessage = mb.CreateProfileSearchPartRequest(0, 5);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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


                numberList = new HashSet <int>()
                {
                    2, 3, 5, 6, 7
                };
                recordIndexOk   = responseMessage.Response.ConversationResponse.ProfileSearchPart.RecordIndex == 0;
                recordCountOk   = responseMessage.Response.ConversationResponse.ProfileSearchPart.RecordCount == numberList.Count;
                profilesCountOk = responseMessage.Response.ConversationResponse.ProfileSearchPart.Profiles.Count == numberList.Count;

                bool fifthPartOk = idOk && statusOk && recordIndexOk && recordCountOk && profilesCountOk;

                profileListOk = CheckProfileList(numberList, responseMessage.Response.ConversationResponse.ProfileSearchPart.Profiles);


                // Step 23 Acceptance
                bool step23Ok = firstPartOk && secondPartOk && thirdPartOk && fourthPartOk && fifthPartOk && profileListOk;

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



                Passed = step1Ok && step2Ok && step3Ok && step4Ok && step5Ok && step6Ok && step7Ok && step8Ok && step9Ok && step10Ok &&
                         step11Ok && step12Ok && step13Ok && step14Ok && step15Ok && step16Ok && step17Ok && step18Ok && step19Ok && step20Ok &&
                         step21Ok && step22Ok && step23Ok;

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

            log.Trace("(-):{0}", res);
            return(res);
        }
Example #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 ServerIp    = (IPAddress)ArgumentValues["Server IP"];
            int       PrimaryPort = (int)ArgumentValues["primary Port"];

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

            bool res = false;

            Passed = false;

            ProtocolClient clientCallee           = new ProtocolClient();
            ProtocolClient clientCalleeAppService = new ProtocolClient(0, SemVer.V100, clientCallee.GetIdentityKeys());

            ProtocolClient clientCaller           = new ProtocolClient();
            ProtocolClient clientCallerAppService = new ProtocolClient(0, SemVer.V100, 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(ServerIp, PrimaryPort, false);

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

                clientCallee.CloseConnection();


                // Establish hosting agreement for identity 1.
                await clientCallee.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool establishHostingOk = await clientCallee.EstablishHostingAsync();

                clientCallee.CloseConnection();


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

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

                bool checkInOk = await clientCallee.CheckInAsync();

                bool initializeProfileOk = await clientCallee.InitializeProfileAsync("Test Identity", null, new GpsLocation(0, 0), 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 && establishHostingOk && checkInOk && initializeProfileOk && addAppServiceOk;

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



                // Step 2
                log.Trace("Step 2");
                await clientCaller.ConnectAsync(ServerIp, (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 serverRequestMessage = await clientCallee.ReceiveMessageAsync();

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

                bool incomingCallNotificationOk = pubKeyOk && serviceNameOk;

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

                Message serverResponseMessage = mbCallee.CreateIncomingCallNotificationResponse(serverRequestMessage);
                await clientCallee.SendMessageAsync(serverResponseMessage);


                // Connect to clAppService and send initialization message.
                await clientCalleeAppService.ConnectAsync(ServerIp, (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(ServerIp, (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);
                string testStr            = "test";
                byte[] invalidCallerToken = Encoding.UTF8.GetBytes(testStr);
                requestMessageAppServiceCaller = mbCallerAppService.CreateApplicationServiceSendMessageRequest(invalidCallerToken, messageBytes);
                uint callerMessage1Id = requestMessageAppServiceCaller.Id;
                await clientCallerAppService.SendMessageAsync(requestMessageAppServiceCaller);

                responseMessageAppServiceCaller = await clientCallerAppService.ReceiveMessageAsync();

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

                bool sendMessageOk = idOk && statusOk;


                // The caller should be disconnected by now, send or receive should throw.
                string callerMessage2 = "Message #2 to callee.";
                messageBytes = Encoding.UTF8.GetBytes(callerMessage2);
                requestMessageAppServiceCaller = mbCallerAppService.CreateApplicationServiceSendMessageRequest(callerToken, messageBytes);

                bool disconnectedOk = false;
                try
                {
                    await clientCallerAppService.SendMessageAsync(requestMessageAppServiceCaller);

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


                // Step 6 Acceptance
                bool step6Ok = sendMessageOk && disconnectedOk;

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


                // Step 7
                log.Trace("Step 7");
                string calleeMessage1 = "Message #1 to CALLER.";
                messageBytes = Encoding.UTF8.GetBytes(calleeMessage1);
                requestMessageAppServiceCallee = mbCalleeAppService.CreateApplicationServiceSendMessageRequest(calleeToken, messageBytes);

                disconnectedOk = false;
                try
                {
                    await clientCalleeAppService.SendMessageAsync(requestMessageAppServiceCallee);

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


                // Step 7 Acceptance
                bool step7Ok = sendMessageOk && disconnectedOk;

                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);
        }
Example #5
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 ServerIp    = (IPAddress)ArgumentValues["Server IP"];
            int       PrimaryPort = (int)ArgumentValues["primary Port"];

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

            bool res = false;

            PassedArray[Index] = false;

            ProtocolClient clientCallee           = new ProtocolClient();
            ProtocolClient clientCalleeAppService = new ProtocolClient(0, SemVer.V100, clientCallee.GetIdentityKeys());

            ProtocolClient clientCaller           = new ProtocolClient();
            ProtocolClient clientCallerAppService = new ProtocolClient(0, SemVer.V100, 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(ServerIp, PrimaryPort, false);

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

                clientCallee.CloseConnection();


                // Establish hosting agreement for identity 1.
                await clientCallee.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool establishHostingOk = await clientCallee.EstablishHostingAsync();

                clientCallee.CloseConnection();


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

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

                bool checkInOk = await clientCallee.CheckInAsync();

                bool initializeProfileOk = await clientCallee.InitializeProfileAsync("Test Identity", null, new GpsLocation(0, 0), 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 && establishHostingOk && checkInOk && initializeProfileOk && addAppServiceOk;

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



                // Step 2
                log.Trace("Step 2");
                await clientCaller.ConnectAsync(ServerIp, (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 serverRequestMessage = await clientCallee.ReceiveMessageAsync();

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

                bool incomingCallNotificationOk = pubKeyOk && serviceNameOk;

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

                Message serverResponseMessage = mbCallee.CreateIncomingCallNotificationResponse(serverRequestMessage);
                await clientCallee.SendMessageAsync(serverResponseMessage);


                // Connect to clAppService and send initialization message.
                await clientCalleeAppService.ConnectAsync(ServerIp, (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(ServerIp, (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);
        }
Example #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 ServerIp    = (IPAddress)ArgumentValues["Server IP"];
            int       PrimaryPort = (int)ArgumentValues["primary Port"];

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

            bool res = false;

            Passed = false;

            ProtocolClient clientCallee           = new ProtocolClient();
            ProtocolClient clientCalleeAppService = new ProtocolClient(0, SemVer.V100, clientCallee.GetIdentityKeys());

            ProtocolClient clientCaller           = new ProtocolClient();
            ProtocolClient clientCallerAppService = new ProtocolClient(0, SemVer.V100, 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(ServerIp, PrimaryPort, false);

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

                clientCallee.CloseConnection();


                // Establish hosting agreement for identity 1.
                await clientCallee.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool establishHostingOk = await clientCallee.EstablishHostingAsync();

                clientCallee.CloseConnection();


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

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

                bool checkInOk = await clientCallee.CheckInAsync();

                bool initializeProfileOk = await clientCallee.InitializeProfileAsync("Test Identity", null, new GpsLocation(0, 0), 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 && establishHostingOk && checkInOk && initializeProfileOk && addAppServiceOk;

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



                // Step 2
                log.Trace("Step 2");
                await clientCaller.ConnectAsync(ServerIp, (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 serverRequestMessage = await clientCallee.ReceiveMessageAsync();

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

                bool incomingCallNotificationOk = pubKeyOk && serviceNameOk;

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

                Message serverResponseMessage = mbCallee.CreateIncomingCallNotificationResponse(serverRequestMessage);
                await clientCallee.SendMessageAsync(serverResponseMessage);


                // Connect to clAppService and send initialization message.
                await clientCalleeAppService.ConnectAsync(ServerIp, (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(ServerIp, (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 serverRequestAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync();

                        SemVer receivedVersion = new SemVer(serverRequestAppServiceCallee.Request.SingleRequest.Version);
                        bool   versionOk       = receivedVersion.Equals(SemVer.V100);

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

                        string receivedMessage = Encoding.UTF8.GetString(serverRequestAppServiceCallee.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);
        }
Example #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 ServerIp          = (IPAddress)ArgumentValues["Server IP"];
            int       ClNonCustomerPort = (int)ArgumentValues["clNonCustomer Port"];

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

            bool res = false;

            Passed = false;

            ProtocolClient        client         = new ProtocolClient();
            List <ProtocolClient> testIdentities = new List <ProtocolClient>();

            for (int i = 0; i < IdentityTypes.Count; i++)
            {
                testIdentities.Add(new ProtocolClient());
            }
            try
            {
                MessageBuilder mb = client.MessageBuilder;

                // Step 1
                log.Trace("Step 1");
                bool error = false;
                for (int i = 0; i < IdentityTypes.Count - 2; i++)
                {
                    ProtocolClient cl = testIdentities[i];
                    await cl.ConnectAsync(ServerIp, ClNonCustomerPort, true);

                    if (!await cl.EstablishHostingAsync(IdentityTypes[i]))
                    {
                        error = true;
                        break;
                    }
                    cl.CloseConnection();
                }

                bool hostingOk = !error;



                await client.ConnectAsync(ServerIp, ClNonCustomerPort, true);

                Message requestMessage = mb.CreateProfileStatsRequest();
                await client.SendMessageAsync(requestMessage);

                Message responseMessage = await client.ReceiveMessageAsync();

                bool idOk     = responseMessage.Id == requestMessage.Id;
                bool statusOk = responseMessage.Response.Status == Status.Ok;
                bool countOk  = responseMessage.Response.SingleResponse.ProfileStats.Stats.Count == 0;

                // Step 1 Acceptance
                bool step1Ok = idOk && statusOk && countOk;

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



                // Step 2
                log.Trace("Step 2");
                for (int i = IdentityTypes.Count - 2; i < IdentityTypes.Count; i++)
                {
                    ProtocolClient cl = testIdentities[i];
                    await cl.ConnectAsync(ServerIp, ClNonCustomerPort, true);

                    if (!await cl.EstablishHostingAsync(IdentityTypes[i]))
                    {
                        error = true;
                        break;
                    }
                    cl.CloseConnection();
                }

                hostingOk = !error;

                requestMessage = mb.CreateProfileStatsRequest();
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;
                countOk  = responseMessage.Response.SingleResponse.ProfileStats.Stats.Count == 0;

                // Step 2 Acceptance
                bool step2Ok = idOk && statusOk && countOk;

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


                Passed = step1Ok && step2Ok;

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

            foreach (ProtocolClient cl in testIdentities)
            {
                cl.Dispose();
            }

            client.Dispose();

            log.Trace("(-):{0}", res);
            return(res);
        }
Example #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 ServerIp          = (IPAddress)ArgumentValues["Server IP"];
            int       ClNonCustomerPort = (int)ArgumentValues["clNonCustomer Port"];
            int       ClCustomerPort    = (int)ArgumentValues["clCustomer Port"];

            log.Trace("(ServerIp:'{0}',ClNonCustomerPort:{1},ClCustomerPort:{2})", ServerIp, 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(ServerIp, ClNonCustomerPort, true);

                bool establishHostingOk = await client.EstablishHostingAsync();

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


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

                bool checkInOk = await client.CheckInAsync();

                byte[]  newProfileServerId = Crypto.Sha256(Encoding.UTF8.GetBytes("test"));
                Message requestMessage     = mb.CreateCancelHostingAgreementRequest(newProfileServerId);
                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   isTargetHostingServerKnownOk = responseMessage.Response.SingleResponse.GetIdentityInformation.IsTargetProfileServerKnown;
                byte[] receivedHostingServerId      = responseMessage.Response.SingleResponse.GetIdentityInformation.TargetProfileServerNetworkId.ToByteArray();
                bool   targetHostingServerIdOk      = StructuralComparisons.StructuralComparer.Compare(receivedHostingServerId, newProfileServerId) == 0;

                bool getIdentityInfoOk = idOk && statusOk && isHostedOk && isTargetHostingServerKnownOk && targetHostingServerIdOk;

                // 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);
        }
Example #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 ServerIp          = (IPAddress)ArgumentValues["Server IP"];
            int       ClNonCustomerPort = (int)ArgumentValues["clNonCustomer Port"];
            int       ClCustomerPort    = (int)ArgumentValues["clCustomer Port"];

            log.Trace("(ServerIp:'{0}',ClNonCustomerPort:{1},ClCustomerPort:{2})", ServerIp, 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(ServerIp, ClNonCustomerPort, true);

                bool establishHostingOk = await client.EstablishHostingAsync();

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


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

                bool checkInOk = await client.CheckInAsync();

                byte[]  newProfileServerId = Encoding.UTF8.GetBytes("test");
                Message requestMessage     = mb.CreateCancelHostingAgreementRequest(newProfileServerId);
                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 == "newProfileServerNetworkId";

                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);
        }
Example #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 ServerIp    = (IPAddress)ArgumentValues["Server IP"];
            int       PrimaryPort = (int)ArgumentValues["primary Port"];

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

            bool res = false;

            Passed = false;

            ProtocolClient client = new ProtocolClient();

            try
            {
                MessageBuilder mb = client.MessageBuilder;

                // Step 1
                log.Trace("Step 1");
                // Get port list.
                await client.ConnectAsync(ServerIp, PrimaryPort, false);

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

                client.CloseConnection();


                ProfilePublicKeys = new List <byte[]>();

                bool profileInitializationOk = true;
                for (int i = 0; i < ProfileNames.Count; i++)
                {
                    ProtocolClient profileClient = new ProtocolClient();
                    ProfilePublicKeys.Add(profileClient.GetIdentityKeys().PublicKey);

                    await profileClient.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                    bool establishHostingOk = await profileClient.EstablishHostingAsync(ProfileTypes[i]);

                    profileClient.CloseConnection();


                    await profileClient.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClCustomer], true);

                    bool checkInOk = await profileClient.CheckInAsync();

                    byte[] imageData = ProfileImages[i] != null?File.ReadAllBytes(ProfileImages[i]) : null;

                    bool initializeProfileOk = await profileClient.InitializeProfileAsync(ProfileNames[i], imageData, ProfileLocations[i], ProfileExtraData[i]);

                    profileInitializationOk = establishHostingOk && checkInOk && initializeProfileOk;
                    profileClient.Dispose();

                    if (!profileInitializationOk)
                    {
                        break;
                    }
                }

                bool step1Ok = listPortsOk && profileInitializationOk;
                log.Trace("Step 1: {0}", step1Ok ? "PASSED" : "FAILED");



                // Step 2
                log.Trace("Step 2");
                await client.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.SrNeighbor], true);

                bool verifyIdentityOk = await client.VerifyIdentityAsync();

                // Start neighborhood initialization process.
                Message requestMessage = mb.CreateStartNeighborhoodInitializationRequest(1, 1);
                await client.SendMessageAsync(requestMessage);

                Message responseMessage = await client.ReceiveMessageAsync();

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

                // Wait for update request.
                Message serverRequestMessage = await client.ReceiveMessageAsync();

                bool typeOk = serverRequestMessage.MessageTypeCase == Message.MessageTypeOneofCase.Request &&
                              serverRequestMessage.Request.ConversationTypeCase == Request.ConversationTypeOneofCase.ConversationRequest &&
                              serverRequestMessage.Request.ConversationRequest.RequestTypeCase == ConversationRequest.RequestTypeOneofCase.NeighborhoodSharedProfileUpdate;

                bool listMatch = CheckProfileList(serverRequestMessage.Request.ConversationRequest.NeighborhoodSharedProfileUpdate.Items);
                bool startNeighborhoodInitializationResponseOk = typeOk && listMatch;

                Message clientResponseMessage = mb.CreateNeighborhoodSharedProfileUpdateResponse(serverRequestMessage);
                await client.SendMessageAsync(clientResponseMessage);


                // Wait for finish request.
                serverRequestMessage = await client.ReceiveMessageAsync();

                typeOk = serverRequestMessage.MessageTypeCase == Message.MessageTypeOneofCase.Request &&
                         serverRequestMessage.Request.ConversationTypeCase == Request.ConversationTypeOneofCase.ConversationRequest &&
                         serverRequestMessage.Request.ConversationRequest.RequestTypeCase == ConversationRequest.RequestTypeOneofCase.FinishNeighborhoodInitialization;

                bool finishNeighborhoodInitializationResponseOk = typeOk;

                clientResponseMessage = mb.CreateFinishNeighborhoodInitializationResponse(serverRequestMessage);
                await client.SendMessageAsync(clientResponseMessage);

                // Step 2 Acceptance
                bool step2Ok = verifyIdentityOk && startNeighborhoodInitializationOk && startNeighborhoodInitializationResponseOk && finishNeighborhoodInitializationResponseOk;

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


                Passed = step1Ok && step2Ok;

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


            log.Trace("(-):{0}", res);
            return(res);
        }
Example #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 ServerIp    = (IPAddress)ArgumentValues["Server IP"];
            int       PrimaryPort = (int)ArgumentValues["primary Port"];

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

            bool res = false;

            Passed = false;

            ProtocolClient client = new ProtocolClient();
            ProtocolClient issuer = new ProtocolClient();

            try
            {
                MessageBuilder mb = client.MessageBuilder;

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

                // Get port list.
                await client.ConnectAsync(ServerIp, PrimaryPort, false);

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

                client.CloseConnection();

                // Establish hosting agreement for primary client.
                await client.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool establishHostingOk = await client.EstablishHostingAsync("Primary");

                client.CloseConnection();

                // Check in primary client.
                await client.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClCustomer], true);

                bool checkInOk = await client.CheckInAsync();

                // Step 1 Acceptance
                bool step1Ok = listPortsOk && establishHostingOk && checkInOk;

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



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

                byte[] primaryPubKey = client.GetIdentityKeys().PublicKey;
                string type          = "Card Type A";

                DateTime validFrom = ProtocolHelper.UnixTimestampMsToDateTime(1479220556000);
                DateTime validTo   = ProtocolHelper.UnixTimestampMsToDateTime(2479220556000);

                bool reqOk = true;
                for (int i = 0; i < RequestCount; i++)
                {
                    SignedRelationshipCard signedCard = issuer.IssueRelationshipCard(primaryPubKey, type, validFrom, validTo);

                    byte[] applicationId = new byte[] { (byte)i };
                    CardApplicationInformation cardApplication = client.CreateRelationshipCardApplication(applicationId, signedCard);

                    Message requestMessage = mb.CreateAddRelatedIdentityRequest(cardApplication, signedCard);
                    await client.SendMessageAsync(requestMessage);

                    Message responseMessage = await client.ReceiveMessageAsync();

                    bool idOk     = responseMessage.Id == requestMessage.Id;
                    bool statusOk = i < 100 ? (responseMessage.Response.Status == Status.Ok) : responseMessage.Response.Status == Status.ErrorQuotaExceeded;

                    reqOk = idOk && statusOk;
                    if (!reqOk)
                    {
                        break;
                    }
                }

                // Step 2 Acceptance
                bool step2Ok = reqOk;

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


                Passed = step1Ok && step2Ok;

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

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

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

            bool res = false;

            Passed = false;

            ProtocolClient client = new ProtocolClient();
            ProtocolClient issuer = new ProtocolClient();

            try
            {
                MessageBuilder mb = client.MessageBuilder;

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

                // Get port list.
                await client.ConnectAsync(ServerIp, PrimaryPort, false);

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

                client.CloseConnection();

                // Establish hosting agreement for primary client.
                await client.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool establishHostingOk = await client.EstablishHostingAsync("Primary");

                client.CloseConnection();

                // Check in primary client.
                await client.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClCustomer], true);

                bool checkInOk = await client.CheckInAsync();

                // Step 1 Acceptance
                bool step1Ok = listPortsOk && establishHostingOk && checkInOk;

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



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

                byte[]   primaryPubKey            = client.GetIdentityKeys().PublicKey;
                string   type                     = "Card Type A";
                DateTime validFrom                = ProtocolHelper.UnixTimestampMsToDateTime(1479220556000);
                DateTime validTo                  = ProtocolHelper.UnixTimestampMsToDateTime(2479220556000);
                SignedRelationshipCard signedCard = issuer.IssueRelationshipCard(primaryPubKey, type, validFrom, validTo);

                byte[] applicationId = new byte[] { 1 };
                CardApplicationInformation cardApplication = client.CreateRelationshipCardApplication(applicationId, signedCard);

                byte[] signature = new byte[16];
                for (int i = 0; i < signature.Length; i++)
                {
                    signature[i] = 0x40;
                }

                Message requestMessage = mb.CreateAddRelatedIdentityRequest(cardApplication, signedCard);
                requestMessage.Request.ConversationRequest.Signature = ProtocolHelper.ByteArrayToByteString(signature);
                await client.SendMessageAsync(requestMessage);

                Message responseMessage = await client.ReceiveMessageAsync();

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

                bool req1Ok = idOk && statusOk;



                type       = "Card Type A";
                validFrom  = ProtocolHelper.UnixTimestampMsToDateTime(1479220556000);
                validTo    = ProtocolHelper.UnixTimestampMsToDateTime(2479220556000);
                signedCard = issuer.IssueRelationshipCard(primaryPubKey, type, validFrom, validTo);

                applicationId   = new byte[] { 2 };
                cardApplication = client.CreateRelationshipCardApplication(applicationId, signedCard);

                requestMessage = mb.CreateAddRelatedIdentityRequest(cardApplication, signedCard);
                signature      = requestMessage.Request.ConversationRequest.Signature.ToByteArray();
                signature[0]  ^= 0x12;
                requestMessage.Request.ConversationRequest.Signature = ProtocolHelper.ByteArrayToByteString(signature);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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

                bool req2Ok = idOk && statusOk;


                type       = "Card Type A";
                validFrom  = ProtocolHelper.UnixTimestampMsToDateTime(1479220556000);
                validTo    = ProtocolHelper.UnixTimestampMsToDateTime(2479220556000);
                signedCard = issuer.IssueRelationshipCard(primaryPubKey, type, validFrom, validTo);

                applicationId   = new byte[] { 3 };
                cardApplication = client.CreateRelationshipCardApplication(applicationId, signedCard);

                requestMessage = mb.CreateAddRelatedIdentityRequest(cardApplication, signedCard);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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

                bool req3Ok = idOk && statusOk;



                type       = "Card Type A";
                validFrom  = ProtocolHelper.UnixTimestampMsToDateTime(1479220556000);
                validTo    = ProtocolHelper.UnixTimestampMsToDateTime(2479220556000);
                signedCard = issuer.IssueRelationshipCard(primaryPubKey, type, validFrom, validTo);

                applicationId   = new byte[] { 3 };
                cardApplication = client.CreateRelationshipCardApplication(applicationId, signedCard);

                requestMessage = mb.CreateAddRelatedIdentityRequest(cardApplication, signedCard);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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

                bool req4Ok = idOk && statusOk;


                type       = "Card Type A";
                validFrom  = ProtocolHelper.UnixTimestampMsToDateTime(1479220556000);
                validTo    = ProtocolHelper.UnixTimestampMsToDateTime(2479220556000);
                signedCard = issuer.IssueRelationshipCard(primaryPubKey, type, validFrom, validTo);

                applicationId   = new byte[] { 4 };
                cardApplication = client.CreateRelationshipCardApplication(applicationId, signedCard);

                byte[] hash = new byte[16];
                for (int i = 0; i < hash.Length; i++)
                {
                    hash[i] = 0x40;
                }

                cardApplication.CardId = ProtocolHelper.ByteArrayToByteString(hash);

                requestMessage = mb.CreateAddRelatedIdentityRequest(cardApplication, signedCard);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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

                bool req5Ok = idOk && statusOk && detailsOk;



                type       = "Card Type A";
                validFrom  = ProtocolHelper.UnixTimestampMsToDateTime(1479220556000);
                validTo    = ProtocolHelper.UnixTimestampMsToDateTime(2479220556000);
                signedCard = issuer.IssueRelationshipCard(primaryPubKey, type, validFrom, validTo);

                applicationId   = new byte[] { 5 };
                cardApplication = client.CreateRelationshipCardApplication(applicationId, signedCard);

                hash     = cardApplication.CardId.ToByteArray();
                hash[0] ^= 0x12;
                cardApplication.CardId = ProtocolHelper.ByteArrayToByteString(hash);

                requestMessage = mb.CreateAddRelatedIdentityRequest(cardApplication, signedCard);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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

                bool req6Ok = idOk && statusOk && detailsOk;



                type       = "Card Type A";
                validFrom  = ProtocolHelper.UnixTimestampMsToDateTime(1479220556000);
                validTo    = ProtocolHelper.UnixTimestampMsToDateTime(2479220556000);
                signedCard = issuer.IssueRelationshipCard(primaryPubKey, type, validFrom, validTo);

                applicationId   = new byte[] { };
                cardApplication = client.CreateRelationshipCardApplication(applicationId, signedCard);

                requestMessage = mb.CreateAddRelatedIdentityRequest(cardApplication, signedCard);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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

                bool req7Ok = idOk && statusOk && detailsOk;


                type       = "Card Type A";
                validFrom  = ProtocolHelper.UnixTimestampMsToDateTime(1479220556000);
                validTo    = ProtocolHelper.UnixTimestampMsToDateTime(2479220556000);
                signedCard = issuer.IssueRelationshipCard(primaryPubKey, type, validFrom, validTo);

                applicationId = new byte[40];
                for (int i = 0; i < applicationId.Length; i++)
                {
                    applicationId[i] = 0x40;
                }

                cardApplication = client.CreateRelationshipCardApplication(applicationId, signedCard);

                requestMessage = mb.CreateAddRelatedIdentityRequest(cardApplication, signedCard);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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

                bool req8Ok = idOk && statusOk && detailsOk;


                type       = "Card Type A";
                validFrom  = ProtocolHelper.UnixTimestampMsToDateTime(1479220556000);
                validTo    = ProtocolHelper.UnixTimestampMsToDateTime(2479220556000);
                signedCard = issuer.IssueRelationshipCard(primaryPubKey, type, validFrom, validTo);
                byte[] issuerPubKey = new byte[10];
                Array.Copy(signedCard.Card.IssuerPublicKey.ToByteArray(), issuerPubKey, issuerPubKey.Length);
                signedCard.Card.IssuerPublicKey = ProtocolHelper.ByteArrayToByteString(issuerPubKey);


                RelationshipCard card = new RelationshipCard()
                {
                    CardId             = ProtocolHelper.ByteArrayToByteString(new byte[32]),
                    Version            = SemVer.V100.ToByteString(),
                    IssuerPublicKey    = signedCard.Card.IssuerPublicKey,
                    RecipientPublicKey = signedCard.Card.RecipientPublicKey,
                    Type      = signedCard.Card.Type,
                    ValidFrom = signedCard.Card.ValidFrom,
                    ValidTo   = signedCard.Card.ValidTo,
                };

                byte[] cardDataToHash = card.ToByteArray();
                byte[] cardId         = Crypto.Sha256(cardDataToHash);
                signedCard.Card.CardId = ProtocolHelper.ByteArrayToByteString(cardId);



                applicationId   = new byte[] { 6 };
                cardApplication = client.CreateRelationshipCardApplication(applicationId, signedCard);

                requestMessage = mb.CreateAddRelatedIdentityRequest(cardApplication, signedCard);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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

                bool req9Ok = idOk && statusOk && detailsOk;



                type             = "Card Type A";
                validFrom        = ProtocolHelper.UnixTimestampMsToDateTime(1479220556000);
                validTo          = ProtocolHelper.UnixTimestampMsToDateTime(2479220556000);
                signedCard       = issuer.IssueRelationshipCard(primaryPubKey, type, validFrom, validTo);
                issuerPubKey     = signedCard.Card.IssuerPublicKey.ToByteArray();
                issuerPubKey[0] ^= 0x12;
                signedCard.Card.IssuerPublicKey = ProtocolHelper.ByteArrayToByteString(issuerPubKey);


                card = new RelationshipCard()
                {
                    CardId             = ProtocolHelper.ByteArrayToByteString(new byte[32]),
                    Version            = SemVer.V100.ToByteString(),
                    IssuerPublicKey    = signedCard.Card.IssuerPublicKey,
                    RecipientPublicKey = signedCard.Card.RecipientPublicKey,
                    Type      = signedCard.Card.Type,
                    ValidFrom = signedCard.Card.ValidFrom,
                    ValidTo   = signedCard.Card.ValidTo,
                };

                cardDataToHash         = card.ToByteArray();
                cardId                 = Crypto.Sha256(cardDataToHash);
                signedCard.Card.CardId = ProtocolHelper.ByteArrayToByteString(cardId);


                applicationId   = new byte[] { 7 };
                cardApplication = client.CreateRelationshipCardApplication(applicationId, signedCard);

                requestMessage = mb.CreateAddRelatedIdentityRequest(cardApplication, signedCard);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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

                bool req10Ok = idOk && statusOk && detailsOk;



                type       = "Card Type A";
                validFrom  = ProtocolHelper.UnixTimestampMsToDateTime(1479220556000);
                validTo    = ProtocolHelper.UnixTimestampMsToDateTime(2479220556000);
                signedCard = issuer.IssueRelationshipCard(primaryPubKey, type, validFrom, validTo);
                byte[] issuerSignature = new byte[20];
                Array.Copy(signedCard.IssuerSignature.ToByteArray(), issuerSignature, issuerSignature.Length);
                signedCard.IssuerSignature = ProtocolHelper.ByteArrayToByteString(issuerSignature);


                applicationId   = new byte[] { 8 };
                cardApplication = client.CreateRelationshipCardApplication(applicationId, signedCard);

                requestMessage = mb.CreateAddRelatedIdentityRequest(cardApplication, signedCard);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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

                bool req11Ok = idOk && statusOk && detailsOk;


                type                       = "Card Type A";
                validFrom                  = ProtocolHelper.UnixTimestampMsToDateTime(1479220556000);
                validTo                    = ProtocolHelper.UnixTimestampMsToDateTime(2479220556000);
                signedCard                 = issuer.IssueRelationshipCard(primaryPubKey, type, validFrom, validTo);
                issuerSignature            = signedCard.IssuerSignature.ToByteArray();
                issuerSignature[0]        ^= 0x12;
                signedCard.IssuerSignature = ProtocolHelper.ByteArrayToByteString(issuerSignature);


                applicationId   = new byte[] { 9 };
                cardApplication = client.CreateRelationshipCardApplication(applicationId, signedCard);

                requestMessage = mb.CreateAddRelatedIdentityRequest(cardApplication, signedCard);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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

                bool req12Ok = idOk && statusOk && detailsOk;


                type       = "Card Type A";
                validFrom  = ProtocolHelper.UnixTimestampMsToDateTime(1479220556000);
                validTo    = ProtocolHelper.UnixTimestampMsToDateTime(2479220556000);
                signedCard = issuer.IssueRelationshipCard(primaryPubKey, type, validFrom, validTo);
                cardId     = new byte[20];
                Array.Copy(signedCard.Card.CardId.ToByteArray(), cardId, cardId.Length);
                signedCard.Card.CardId = ProtocolHelper.ByteArrayToByteString(cardId);


                applicationId   = new byte[] { 10 };
                cardApplication = client.CreateRelationshipCardApplication(applicationId, signedCard);

                requestMessage = mb.CreateAddRelatedIdentityRequest(cardApplication, signedCard);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk      = responseMessage.Id == requestMessage.Id;
                statusOk  = responseMessage.Response.Status == Status.ErrorInvalidValue;
                detailsOk = responseMessage.Response.Details == "signedCard.card.cardId";

                bool req13Ok = idOk && statusOk && detailsOk;


                type                   = "Card Type A";
                validFrom              = ProtocolHelper.UnixTimestampMsToDateTime(1479220556000);
                validTo                = ProtocolHelper.UnixTimestampMsToDateTime(2479220556000);
                signedCard             = issuer.IssueRelationshipCard(primaryPubKey, type, validFrom, validTo);
                cardId                 = signedCard.Card.CardId.ToByteArray();
                cardId[0]             ^= 0x12;
                signedCard.Card.CardId = ProtocolHelper.ByteArrayToByteString(cardId);


                applicationId   = new byte[] { 11 };
                cardApplication = client.CreateRelationshipCardApplication(applicationId, signedCard);

                requestMessage = mb.CreateAddRelatedIdentityRequest(cardApplication, signedCard);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk      = responseMessage.Id == requestMessage.Id;
                statusOk  = responseMessage.Response.Status == Status.ErrorInvalidValue;
                detailsOk = responseMessage.Response.Details == "signedCard.card.cardId";

                bool req14Ok = idOk && statusOk && detailsOk;


                type      = "Card Type A";
                validFrom = ProtocolHelper.UnixTimestampMsToDateTime(1479220556000);
                validTo   = ProtocolHelper.UnixTimestampMsToDateTime(2479220556000);
                byte[] rcptPubKey = new byte[20];
                Array.Copy(signedCard.Card.RecipientPublicKey.ToByteArray(), rcptPubKey, rcptPubKey.Length);
                signedCard = issuer.IssueRelationshipCard(rcptPubKey, type, validFrom, validTo);


                applicationId   = new byte[] { 12 };
                cardApplication = client.CreateRelationshipCardApplication(applicationId, signedCard);

                requestMessage = mb.CreateAddRelatedIdentityRequest(cardApplication, signedCard);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk      = responseMessage.Id == requestMessage.Id;
                statusOk  = responseMessage.Response.Status == Status.ErrorInvalidValue;
                detailsOk = responseMessage.Response.Details == "signedCard.card.recipientPublicKey";

                bool req15Ok = idOk && statusOk && detailsOk;


                type       = "Card Type A";
                validFrom  = ProtocolHelper.UnixTimestampMsToDateTime(1479220556000);
                validTo    = ProtocolHelper.UnixTimestampMsToDateTime(2479220556000);
                rcptPubKey = new byte[primaryPubKey.Length];
                Array.Copy(primaryPubKey, rcptPubKey, rcptPubKey.Length);
                rcptPubKey[0] ^= 0x12;
                signedCard     = issuer.IssueRelationshipCard(rcptPubKey, type, validFrom, validTo);

                applicationId   = new byte[] { 13 };
                cardApplication = client.CreateRelationshipCardApplication(applicationId, signedCard);

                requestMessage = mb.CreateAddRelatedIdentityRequest(cardApplication, signedCard);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk      = responseMessage.Id == requestMessage.Id;
                statusOk  = responseMessage.Response.Status == Status.ErrorInvalidValue;
                detailsOk = responseMessage.Response.Details == "signedCard.card.recipientPublicKey";

                bool req16Ok = idOk && statusOk && detailsOk;



                type       = "Card Type A";
                validFrom  = ProtocolHelper.UnixTimestampMsToDateTime(1479220556000);
                validTo    = ProtocolHelper.UnixTimestampMsToDateTime(1479220555000);
                signedCard = issuer.IssueRelationshipCard(primaryPubKey, type, validFrom, validTo);

                applicationId   = new byte[] { 14 };
                cardApplication = client.CreateRelationshipCardApplication(applicationId, signedCard);

                requestMessage = mb.CreateAddRelatedIdentityRequest(cardApplication, signedCard);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk      = responseMessage.Id == requestMessage.Id;
                statusOk  = responseMessage.Response.Status == Status.ErrorInvalidValue;
                detailsOk = responseMessage.Response.Details == "signedCard.card.validFrom";

                bool req17Ok = idOk && statusOk && detailsOk;



                type       = new string('a', 70);
                validFrom  = ProtocolHelper.UnixTimestampMsToDateTime(1479220556000);
                validTo    = ProtocolHelper.UnixTimestampMsToDateTime(2479220556000);
                signedCard = issuer.IssueRelationshipCard(primaryPubKey, type, validFrom, validTo);

                applicationId   = new byte[] { 15 };
                cardApplication = client.CreateRelationshipCardApplication(applicationId, signedCard);

                requestMessage = mb.CreateAddRelatedIdentityRequest(cardApplication, signedCard);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk      = responseMessage.Id == requestMessage.Id;
                statusOk  = responseMessage.Response.Status == Status.ErrorInvalidValue;
                detailsOk = responseMessage.Response.Details == "signedCard.card.type";

                bool req18Ok = idOk && statusOk && detailsOk;


                type       = new string('ɐ', 35);
                validFrom  = ProtocolHelper.UnixTimestampMsToDateTime(1479220556000);
                validTo    = ProtocolHelper.UnixTimestampMsToDateTime(2479220556000);
                signedCard = issuer.IssueRelationshipCard(primaryPubKey, type, validFrom, validTo);

                applicationId   = new byte[] { 16 };
                cardApplication = client.CreateRelationshipCardApplication(applicationId, signedCard);

                requestMessage = mb.CreateAddRelatedIdentityRequest(cardApplication, signedCard);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk      = responseMessage.Id == requestMessage.Id;
                statusOk  = responseMessage.Response.Status == Status.ErrorInvalidValue;
                detailsOk = responseMessage.Response.Details == "signedCard.card.type";

                bool req19Ok = idOk && statusOk && detailsOk;


                type       = "Card Type A";
                validFrom  = ProtocolHelper.UnixTimestampMsToDateTime(1479220556000);
                validTo    = ProtocolHelper.UnixTimestampMsToDateTime(2479220556000);
                signedCard = issuer.IssueRelationshipCard(new byte[] { 0, 0, 0 }, primaryPubKey, type, validFrom, validTo);

                applicationId   = new byte[] { 17 };
                cardApplication = client.CreateRelationshipCardApplication(applicationId, signedCard);

                requestMessage = mb.CreateAddRelatedIdentityRequest(cardApplication, signedCard);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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

                bool req20Ok = idOk && statusOk && detailsOk;


                type       = "Card Type A";
                validFrom  = ProtocolHelper.UnixTimestampMsToDateTime(1479220556000);
                validTo    = ProtocolHelper.UnixTimestampMsToDateTime(2479220556000);
                signedCard = issuer.IssueRelationshipCard(new byte[] { 1, 0 }, primaryPubKey, type, validFrom, validTo);

                applicationId   = new byte[] { 18 };
                cardApplication = client.CreateRelationshipCardApplication(applicationId, signedCard);

                requestMessage = mb.CreateAddRelatedIdentityRequest(cardApplication, signedCard);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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

                bool req21Ok = idOk && statusOk && detailsOk;


                type       = "Card Type A";
                validFrom  = ProtocolHelper.UnixTimestampMsToDateTime(1479220556000);
                validTo    = ProtocolHelper.UnixTimestampMsToDateTime(2479220556000);
                signedCard = issuer.IssueRelationshipCard(new byte[] { 1, 0, 0, 0 }, primaryPubKey, type, validFrom, validTo);

                applicationId   = new byte[] { 19 };
                cardApplication = client.CreateRelationshipCardApplication(applicationId, signedCard);

                requestMessage = mb.CreateAddRelatedIdentityRequest(cardApplication, signedCard);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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

                bool req22Ok = idOk && statusOk && detailsOk;


                type      = "Card Type A";
                validFrom = ProtocolHelper.UnixTimestampMsToDateTime(1479220556000);
                validTo   = ProtocolHelper.UnixTimestampMsToDateTime(2479220556000);
                byte[] badPubKey = new byte[130];
                for (int i = 0; i < badPubKey.Length; i++)
                {
                    badPubKey[i] = 0x40;
                }

                RelationshipCard badIssuerKeyCard = new RelationshipCard()
                {
                    CardId             = ProtocolHelper.ByteArrayToByteString(new byte[32]),
                    Version            = SemVer.V100.ToByteString(),
                    IssuerPublicKey    = ProtocolHelper.ByteArrayToByteString(badPubKey),
                    RecipientPublicKey = ProtocolHelper.ByteArrayToByteString(primaryPubKey),
                    Type      = type,
                    ValidFrom = ProtocolHelper.DateTimeToUnixTimestampMs(validFrom),
                    ValidTo   = ProtocolHelper.DateTimeToUnixTimestampMs(validTo)
                };

                signedCard = issuer.IssueRelationshipCard(badIssuerKeyCard);

                applicationId   = new byte[] { 20 };
                cardApplication = client.CreateRelationshipCardApplication(applicationId, signedCard);

                requestMessage = mb.CreateAddRelatedIdentityRequest(cardApplication, signedCard);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk      = responseMessage.Id == requestMessage.Id;
                statusOk  = responseMessage.Response.Status == Status.ErrorInvalidValue;
                detailsOk = responseMessage.Response.Details == "signedCard.card.issuerPublicKey";

                bool req23Ok = idOk && statusOk && detailsOk;



                // Step 2 Acceptance
                bool step2Ok = req1Ok && req2Ok && req3Ok && req4Ok && req5Ok && req6Ok && req7Ok && req8Ok && req9Ok && req10Ok &&
                               req11Ok && req12Ok && req13Ok && req14Ok && req15Ok && req16Ok && req17Ok && req18Ok && req19Ok && req20Ok &&
                               req21Ok && req22Ok && req23Ok;

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



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

                applicationId  = new byte[] { 21 };
                requestMessage = mb.CreateRemoveRelatedIdentityRequest(applicationId);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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


                type           = new string('a', 70);
                requestMessage = mb.CreateGetIdentityRelationshipsInformationRequest(client.GetIdentityId(), true, type, null);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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

                req1Ok = idOk && statusOk && detailsOk;


                type           = new string('ɐ', 35);
                requestMessage = mb.CreateGetIdentityRelationshipsInformationRequest(client.GetIdentityId(), true, type, null);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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

                req2Ok = idOk && statusOk && detailsOk;


                // Step 3 Acceptance
                bool step3Ok = removeOk && req1Ok && req2Ok;

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



                Passed = step1Ok && step2Ok && step3Ok;


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

            log.Trace("(-):{0}", res);
            return(res);
        }
Example #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 ServerIp          = (IPAddress)ArgumentValues["Server IP"];
            int       ClNonCustomerPort = (int)ArgumentValues["clNonCustomer Port"];
            int       ClCustomerPort    = (int)ArgumentValues["clCustomer Port"];

            log.Trace("(ServerIp:'{0}',ClNonCustomerPort:{1},ClCustomerPort:{2})", ServerIp, 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(ServerIp, ClNonCustomerPort, true);

                bool establishHostingOk = await client.EstablishHostingAsync();

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


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

                bool checkInOk = await client.CheckInAsync();

                Message requestMessage = mb.CreateUpdateProfileRequest(null, "Test Identity", null, new GpsLocation(1, 2), 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(SemVer.V100, null, null, new GpsLocation(1, 2), 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(SemVer.V100, "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 SemVer(0, 0, 0), "Test Identity", null, new GpsLocation(1, 2), 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 SemVer(255, 0, 0), "Test Identity", null, new GpsLocation(1, 2), 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(SemVer.V100, "", null, new GpsLocation(1, 2), 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(SemVer.V100, name, null, new GpsLocation(1, 2), 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(SemVer.V100, name, null, new GpsLocation(1, 2), 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}PS04007-too-big.jpg", Path.DirectorySeparatorChar));
                requestMessage = mb.CreateUpdateProfileRequest(SemVer.V100, "Test Identity", imageData, new GpsLocation(1, 2), 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}PS04007-not-image.jpg", Path.DirectorySeparatorChar));
                requestMessage = mb.CreateUpdateProfileRequest(SemVer.V100, "Test Identity", imageData, new GpsLocation(1, 2), 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(SemVer.V100, "Test Identity", null, new GpsLocation(1, 2), 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(SemVer.V100, "Test Identity", null, new GpsLocation(1, 2), 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(SemVer.V100, "Test Identity", null, new GpsLocation(1, 2), 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;

                int badLatitude = (int)(GpsLocation.LatitudeMin * GpsLocation.LocationTypeFactor - 1);
                requestMessage = mb.CreateUpdateProfileRequest(null, null, null, new GpsLocation(badLatitude, 2), null);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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

                bool updateProfileOk15 = idOk && statusOk && detailsOk;


                int badLongitude = (int)(GpsLocation.LongitudeMax * GpsLocation.LocationTypeFactor + 1);
                requestMessage = mb.CreateUpdateProfileRequest(null, null, null, new GpsLocation(0, badLongitude), null);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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

                bool updateProfileOk16 = idOk && statusOk && detailsOk;


                requestMessage = mb.CreateUpdateProfileRequest(null, null, null, new GpsLocation(badLatitude, badLongitude), null);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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

                bool updateProfileOk17 = idOk && statusOk && detailsOk;

                // Step 2 Acceptance

                bool step2Ok = checkInOk && updateProfileOk1 && updateProfileOk2 && updateProfileOk3 && updateProfileOk4 && updateProfileOk5 && updateProfileOk6 && updateProfileOk7 && updateProfileOk8 &&
                               updateProfileOk9 && updateProfileOk10 && updateProfileOk11 && updateProfileOk12 && updateProfileOk13 && updateProfileOk14 && updateProfileOk15 && updateProfileOk16 && updateProfileOk17;


                Passed = step1Ok && step2Ok;

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

            log.Trace("(-):{0}", res);
            return(res);
        }
Example #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 ServerIp          = (IPAddress)ArgumentValues["Server IP"];
            int       ClNonCustomerPort = (int)ArgumentValues["clNonCustomer Port"];
            int       ClCustomerPort    = (int)ArgumentValues["clCustomer Port"];

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

            bool res = false;

            Passed = false;

            ProtocolClient        client         = new ProtocolClient();
            List <ProtocolClient> testIdentities = new List <ProtocolClient>();

            for (int i = 0; i < IdentityTypes.Count; i++)
            {
                testIdentities.Add(new ProtocolClient());
            }
            try
            {
                MessageBuilder mb = client.MessageBuilder;

                // Step 1
                log.Trace("Step 1");
                bool error = false;
                for (int i = 0; i < IdentityTypes.Count - 2; i++)
                {
                    ProtocolClient cl = testIdentities[i];
                    await cl.ConnectAsync(ServerIp, ClNonCustomerPort, true);

                    if (!await cl.EstablishHostingAsync(IdentityTypes[i]))
                    {
                        error = true;
                        break;
                    }
                    cl.CloseConnection();
                }

                bool hostingOk = !error;

                error = false;
                for (int i = 0; i < IdentityTypes.Count - 3; i++)
                {
                    ProtocolClient cl = testIdentities[i];
                    await cl.ConnectAsync(ServerIp, ClCustomerPort, true);

                    if (await cl.CheckInAsync())
                    {
                        if (!await cl.InitializeProfileAsync(i.ToString(), null, new GpsLocation(1, 1), null))
                        {
                            error = true;
                            break;
                        }
                    }
                    else
                    {
                        error = true;
                        break;
                    }
                    cl.CloseConnection();
                }
                bool profileInitOk = !error;


                await client.ConnectAsync(ServerIp, ClNonCustomerPort, true);

                Message requestMessage = mb.CreateProfileStatsRequest();
                await client.SendMessageAsync(requestMessage);

                Message responseMessage = await client.ReceiveMessageAsync();

                bool idOk     = responseMessage.Id == requestMessage.Id;
                bool statusOk = responseMessage.Response.Status == Status.Ok;
                bool countOk  = responseMessage.Response.SingleResponse.ProfileStats.Stats.Count == 5;

                List <ProfileStatsItem> controlList = new List <ProfileStatsItem>()
                {
                    new ProfileStatsItem()
                    {
                        IdentityType = "Type A", Count = 2
                    },
                    new ProfileStatsItem()
                    {
                        IdentityType = "Type B", Count = 3
                    },
                    new ProfileStatsItem()
                    {
                        IdentityType = "Type Alpha", Count = 1
                    },
                    new ProfileStatsItem()
                    {
                        IdentityType = "Type A B", Count = 1
                    },
                    new ProfileStatsItem()
                    {
                        IdentityType = "Type Beta", Count = 1
                    },
                };

                foreach (ProfileStatsItem item in responseMessage.Response.SingleResponse.ProfileStats.Stats)
                {
                    ProfileStatsItem controlItem = controlList.Find(i => (i.IdentityType == item.IdentityType) && (i.Count == item.Count));
                    if (!controlList.Remove(controlItem))
                    {
                        error = true;
                        break;
                    }
                }

                bool contentOk = (controlList.Count == 0) && !error;

                // Step 1 Acceptance
                bool step1Ok = idOk && statusOk && hostingOk && profileInitOk && countOk && contentOk;

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



                // Step 2
                log.Trace("Step 2");
                for (int i = IdentityTypes.Count - 2; i < IdentityTypes.Count; i++)
                {
                    ProtocolClient cl = testIdentities[i];
                    await cl.ConnectAsync(ServerIp, ClNonCustomerPort, true);

                    if (!await cl.EstablishHostingAsync(IdentityTypes[i]))
                    {
                        error = true;
                        break;
                    }
                    cl.CloseConnection();
                }

                hostingOk = !error;

                error = false;
                for (int i = IdentityTypes.Count - 2; i < IdentityTypes.Count; i++)
                {
                    ProtocolClient cl = testIdentities[i];
                    await cl.ConnectAsync(ServerIp, ClCustomerPort, true);

                    if (await cl.CheckInAsync())
                    {
                        if (!await cl.InitializeProfileAsync(i.ToString(), null, new GpsLocation(1, 1), null))
                        {
                            error = true;
                            break;
                        }
                    }
                    else
                    {
                        error = true;
                        break;
                    }
                    cl.CloseConnection();
                }
                profileInitOk = !error;

                requestMessage = mb.CreateProfileStatsRequest();
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;
                countOk  = responseMessage.Response.SingleResponse.ProfileStats.Stats.Count == 6;

                controlList = new List <ProfileStatsItem>()
                {
                    new ProfileStatsItem()
                    {
                        IdentityType = "Type A", Count = 2
                    },
                    new ProfileStatsItem()
                    {
                        IdentityType = "Type B", Count = 3
                    },
                    new ProfileStatsItem()
                    {
                        IdentityType = "Type Alpha", Count = 1
                    },
                    new ProfileStatsItem()
                    {
                        IdentityType = "Type A B", Count = 2
                    },
                    new ProfileStatsItem()
                    {
                        IdentityType = "Type Beta", Count = 1
                    },
                    new ProfileStatsItem()
                    {
                        IdentityType = "Type C", Count = 1
                    },
                };

                foreach (ProfileStatsItem item in responseMessage.Response.SingleResponse.ProfileStats.Stats)
                {
                    ProfileStatsItem controlItem = controlList.Find(i => (i.IdentityType == item.IdentityType) && (i.Count == item.Count));
                    if (!controlList.Remove(controlItem))
                    {
                        error = true;
                        break;
                    }
                }

                contentOk = (controlList.Count == 0) && !error;

                // Step 2 Acceptance
                bool step2Ok = idOk && statusOk && hostingOk && profileInitOk && countOk && contentOk;

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


                Passed = step1Ok && step2Ok;

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

            foreach (ProtocolClient cl in testIdentities)
            {
                cl.Dispose();
            }

            client.Dispose();

            log.Trace("(-):{0}", res);
            return(res);
        }
Example #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 ServerIp    = (IPAddress)ArgumentValues["Server IP"];
            int       PrimaryPort = (int)ArgumentValues["primary Port"];
            int       CanPort     = (int)ArgumentValues["CAN Port"];

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

            bool res = false;

            Passed = false;

            ProtocolClient client = new ProtocolClient();

            try
            {
                MessageBuilder mb = client.MessageBuilder;

                // Step 1
                log.Trace("Step 1");
                // Get port list.
                await client.ConnectAsync(ServerIp, PrimaryPort, false);

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

                client.CloseConnection();

                await client.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool hostingOk = await client.EstablishHostingAsync("Test");

                client.CloseConnection();

                await client.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClCustomer], true);

                bool checkInOk = await client.CheckInAsync();

                bool step1Ok = listPortsOk && hostingOk && checkInOk;
                log.Trace("Step 1: {0}", step1Ok ? "PASSED" : "FAILED");



                // Step 2
                log.Trace("Step 2");
                byte[]             serverId   = Crypto.Sha256(client.ServerKey);
                List <CanKeyValue> clientData = new List <CanKeyValue>()
                {
                    new CanKeyValue()
                    {
                        Key = "key1", StringValue = "value 1"
                    },
                    new CanKeyValue()
                    {
                        Key = "key2", Uint32Value = 2
                    },
                    new CanKeyValue()
                    {
                        Key = "key3", BoolValue = true
                    },
                    new CanKeyValue()
                    {
                        Key = "key4", BinaryValue = ProtocolHelper.ByteArrayToByteString(new byte[] { 1, 2, 3 })
                    },
                };

                CanIdentityData identityData1 = new CanIdentityData()
                {
                    HostingServerId = ProtocolHelper.ByteArrayToByteString(serverId)
                };
                identityData1.KeyValueList.AddRange(clientData);

                Message requestMessage = mb.CreateCanStoreDataRequest(identityData1);
                await client.SendMessageAsync(requestMessage);

                Message responseMessage = await client.ReceiveMessageAsync();

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

                byte[] objectHash1 = responseMessage.Response.ConversationResponse.CanStoreData.Hash.ToByteArray();


                string objectPath1 = client.CreateIpfsPathFromHash(objectHash1);
                log.Trace("Object path 1 is '{0}'.", objectPath1);

                string       validityString = DateTime.UtcNow.AddMonths(1).ToString("yyyy-MM-dd'T'HH:mm:ss.fffK", DateTimeFormatInfo.InvariantInfo);
                CanIpnsEntry ipnsRecord     = new CanIpnsEntry()
                {
                    Value        = ProtocolHelper.ByteArrayToByteString(Encoding.UTF8.GetBytes(objectPath1)),
                    ValidityType = CanIpnsEntry.Types.ValidityType.Eol,
                    Validity     = ProtocolHelper.ByteArrayToByteString(Encoding.UTF8.GetBytes(validityString)),
                    Sequence     = 1,
                    Ttl          = 6000000000,
                };
                ipnsRecord.Signature = ProtocolHelper.ByteArrayToByteString(client.CreateIpnsRecordSignature(ipnsRecord));

                requestMessage = mb.CreateCanPublishIpnsRecordRequest(ipnsRecord);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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



                // Step 2 Acceptance
                bool step2Ok = canStoreDataOk && canPublishIpnsRecordOk;

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



                // Step 3
                log.Trace("Step 3");
                IPEndPoint canEndPoint = new IPEndPoint(ServerIp, CanPort);
                byte[]     clientCanId = client.CanPublicKeyToId(client.GetIdentityKeys().PublicKey);
                string     ipnsPath    = client.CreateIpnsPathFromHash(clientCanId);

                ProtocolClient.CanIpnsResolveResult canIpnsResolveResult = await client.CanIpnsResolve(canEndPoint, ipnsPath);

                string canObjectPath = canIpnsResolveResult.Path;
                bool   objectPathOk  = canObjectPath == objectPath1;
                bool   resolveOk     = canIpnsResolveResult.Success && objectPathOk;

                ProtocolClient.CanCatResult canCatResult = await client.CanGetObject(canEndPoint, canObjectPath);

                byte[] receivedData = canCatResult.Data;
                byte[] expectedData = identityData1.ToByteArray();
                bool   dataOk       = StructuralComparisons.StructuralComparer.Compare(receivedData, expectedData) == 0;
                bool   catOk        = canCatResult.Success && dataOk;

                // Step 3 Acceptance
                bool step3Ok = resolveOk && catOk;

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



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

                ipnsRecord.Sequence  = 2;
                ipnsRecord.Signature = ProtocolHelper.ByteArrayToByteString(client.CreateIpnsRecordSignature(ipnsRecord));

                requestMessage = mb.CreateCanPublishIpnsRecordRequest(ipnsRecord);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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


                canIpnsResolveResult = await client.CanIpnsResolve(canEndPoint, ipnsPath);

                canObjectPath = canIpnsResolveResult.Path;
                objectPathOk  = canObjectPath == objectPath1;
                resolveOk     = canIpnsResolveResult.Success && objectPathOk;

                // Step 4 Acceptance
                bool step4Ok = canPublishIpnsRecordOk && resolveOk;

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


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

                byte[] valX = new byte[50000];
                for (int i = 0; i < valX.Length; i++)
                {
                    valX[i] = 0x30;
                }

                clientData = new List <CanKeyValue>()
                {
                    new CanKeyValue()
                    {
                        Key = "key1", StringValue = "value 1"
                    },
                    new CanKeyValue()
                    {
                        Key = "key2", Uint32Value = 3
                    },
                    new CanKeyValue()
                    {
                        Key = "key3", BoolValue = false
                    },
                    new CanKeyValue()
                    {
                        Key = "keyX", BinaryValue = ProtocolHelper.ByteArrayToByteString(valX)
                    },
                };

                CanIdentityData identityData2 = new CanIdentityData()
                {
                    HostingServerId = ProtocolHelper.ByteArrayToByteString(serverId)
                };
                identityData2.KeyValueList.AddRange(clientData);


                requestMessage = mb.CreateCanStoreDataRequest(identityData2);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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

                byte[] objectHash2 = responseMessage.Response.ConversationResponse.CanStoreData.Hash.ToByteArray();


                string objectPath2 = client.CreateIpfsPathFromHash(objectHash2);
                log.Trace("Object path 2 is '{0}'.", objectPath2);

                ipnsRecord.Sequence  = 3;
                ipnsRecord.Value     = ProtocolHelper.ByteArrayToByteString(Encoding.UTF8.GetBytes(objectPath2));
                ipnsRecord.Signature = ProtocolHelper.ByteArrayToByteString(client.CreateIpnsRecordSignature(ipnsRecord));

                requestMessage = mb.CreateCanPublishIpnsRecordRequest(ipnsRecord);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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


                // Step 5 Acceptance
                bool step5Ok = canStoreDataOk && canPublishIpnsRecordOk;

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


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

                await Task.Delay(10000);

                canIpnsResolveResult = await client.CanIpnsResolve(canEndPoint, ipnsPath);

                canObjectPath = canIpnsResolveResult.Path;
                objectPathOk  = canObjectPath == objectPath2;
                resolveOk     = canIpnsResolveResult.Success && objectPathOk;

                canCatResult = await client.CanGetObject(canEndPoint, canObjectPath);

                receivedData = canCatResult.Data;
                expectedData = identityData2.ToByteArray();
                dataOk       = StructuralComparisons.StructuralComparer.Compare(receivedData, expectedData) == 0;
                catOk        = canCatResult.Success && dataOk;

                // Step 6 Acceptance
                bool step6Ok = resolveOk && catOk;

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


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

                requestMessage = mb.CreateCanStoreDataRequest(null);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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

                ProtocolClient.CanDeleteResult canDeleteResult = await client.CanDeleteObject(canEndPoint, canObjectPath);

                bool pinsOk   = (canDeleteResult.Pins == null) || (canDeleteResult.Pins.Length == 0);
                bool deleteOk = canDeleteResult.Success && pinsOk;

                // Step 7 Acceptance
                bool step7Ok = canStoreDataOk && deleteOk;

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



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

                canDeleteResult = await client.CanDeleteObject(canEndPoint, objectPath1);

                pinsOk   = (canDeleteResult.Pins == null) || (canDeleteResult.Pins.Length == 0);
                deleteOk = canDeleteResult.Success && pinsOk;

                // Step 8 Acceptance
                bool step8Ok = deleteOk;

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



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

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


            log.Trace("(-):{0}", res);
            return(res);
        }
Example #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 ServerIp          = (IPAddress)ArgumentValues["Server IP"];
            int       ClNonCustomerPort = (int)ArgumentValues["clNonCustomer Port"];
            int       ClCustomerPort    = (int)ArgumentValues["clCustomer Port"];

            log.Trace("(ServerIp:'{0}',ClNonCustomerPort:{1},ClCustomerPort:{2})", ServerIp, 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(ServerIp, ClNonCustomerPort, true);

                bool establishHostingOk = await client.EstablishHostingAsync();

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


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

                bool checkInOk = await client.CheckInAsync();


                Message requestMessage = mb.CreateUpdateProfileRequest(SemVer.V100, "Test Identity", null, new GpsLocation(0, 0), 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;
                SemVer receivedVersion = new SemVer(responseMessage.Response.SingleResponse.GetIdentityInformation.Version);
                bool   versionOk       = receivedVersion.Equals(SemVer.V100);

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


                bool getIdentityInfoOk1 = idOk && statusOk && isHostedOk && isOnlineOk && pubKeyOk && versionOk && 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;
                receivedVersion = new SemVer(responseMessage.Response.SingleResponse.GetIdentityInformation.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

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


                bool getIdentityInfoOk2 = idOk && statusOk && isHostedOk && isOnlineOk && pubKeyOk && versionOk && 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;
                receivedVersion = new SemVer(responseMessage.Response.SingleResponse.GetIdentityInformation.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

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


                bool getIdentityInfoOk3 = idOk && statusOk && isHostedOk && isOnlineOk && pubKeyOk && versionOk && 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;
                receivedVersion = new SemVer(responseMessage.Response.SingleResponse.GetIdentityInformation.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

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


                bool getIdentityInfoOk4 = idOk && statusOk && isHostedOk && isOnlineOk && pubKeyOk && versionOk && 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;
                receivedVersion = new SemVer(responseMessage.Response.SingleResponse.GetIdentityInformation.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

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


                bool getIdentityInfoOk5 = idOk && statusOk && isHostedOk && isOnlineOk && pubKeyOk && versionOk && 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;
                receivedVersion = new SemVer(responseMessage.Response.SingleResponse.GetIdentityInformation.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

                expectedAsList = new HashSet <string>(StringComparer.Ordinal)
                {
                    "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, StringComparer.Ordinal);
                appServicesOk  = expectedAsList.SetEquals(responseMessage.Response.SingleResponse.GetIdentityInformation.ApplicationServices);


                bool getIdentityInfoOk7 = idOk && statusOk && isHostedOk && isOnlineOk && pubKeyOk && versionOk && 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;
                receivedVersion = new SemVer(responseMessage.Response.SingleResponse.GetIdentityInformation.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

                expectedAsList = new HashSet <string>(StringComparer.Ordinal)
                {
                    "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, StringComparer.Ordinal);
                appServicesOk  = expectedAsList.SetEquals(responseMessage.Response.SingleResponse.GetIdentityInformation.ApplicationServices);


                bool getIdentityInfoOk8 = idOk && statusOk && isHostedOk && isOnlineOk && pubKeyOk && versionOk && 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);
        }
Example #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 ServerIp    = (IPAddress)ArgumentValues["Server IP"];
            int       PrimaryPort = (int)ArgumentValues["primary Port"];

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

            bool res = false;

            Passed = false;

            ProtocolClient clientCallee           = new ProtocolClient();
            ProtocolClient clientCalleeAppService = new ProtocolClient(0, SemVer.V100, clientCallee.GetIdentityKeys());

            ProtocolClient clientCaller           = new ProtocolClient();
            ProtocolClient clientCallerAppService = new ProtocolClient(0, SemVer.V100, 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(ServerIp, PrimaryPort, false);

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

                clientCallee.CloseConnection();


                // Establish hosting agreement for identity 1.
                await clientCallee.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool establishHostingOk = await clientCallee.EstablishHostingAsync();

                clientCallee.CloseConnection();


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

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

                bool checkInOk = await clientCallee.CheckInAsync();

                bool initializeProfileOk = await clientCallee.InitializeProfileAsync("Test Identity", null, new GpsLocation(0, 0), 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 && establishHostingOk && checkInOk && initializeProfileOk && addAppServiceOk;

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



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

                bool verifyIdentityOk = await clientCaller.VerifyIdentityAsync();


                Message requestMessage = mbCaller.CreateGetIdentityInformationRequest(identityIdCallee, false, false, true);
                await clientCaller.SendMessageAsync(requestMessage);

                Message responseMessage = await clientCaller.ReceiveMessageAsync();

                bool idOk     = responseMessage.Id == requestMessage.Id;
                bool 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, pubKeyCallee) == 0;

                HashSet <string> receivedAsList    = new HashSet <string>(responseMessage.Response.SingleResponse.GetIdentityInformation.ApplicationServices, StringComparer.Ordinal);
                bool             appServiceReadyOk = receivedAsList.Contains(serviceName);

                bool getInfoOk = idOk && statusOk && isHostedOk && isOnlineOk && pubKeyOk && appServiceReadyOk;


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

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



                // Step 3
                log.Trace("Step 3");
                requestMessage = mbCaller.CreateCallIdentityApplicationServiceRequest(identityIdCallee, serviceName);
                await clientCaller.SendMessageAsync(requestMessage);

                // Step 3 Acceptance
                bool step3Ok = true;

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



                // Step 4
                log.Trace("Step 4");
                Message serverRequestMessage = await clientCallee.ReceiveMessageAsync();

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

                bool incomingCallNotificationOk = pubKeyOk && serviceNameOk;

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

                Message serverResponseMessage = mbCallee.CreateIncomingCallNotificationResponse(serverRequestMessage);
                await clientCallee.SendMessageAsync(serverResponseMessage);


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

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


                // Step 4 Acceptance
                bool step4Ok = incomingCallNotificationOk;

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


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

                idOk     = responseMessage.Id == requestMessage.Id;
                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(ServerIp, (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 5 Acceptance
                bool step5Ok = callIdentityOk && initAppServiceMessageOk;

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



                // Step 6
                log.Trace("Step 6");
                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 6 Acceptance
                bool step6Ok = appServiceSendOk;

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


                // Step 7
                log.Trace("Step 7");
                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);

                string callerMessage2 = "Message #2 to callee.";
                messageBytes = Encoding.UTF8.GetBytes(callerMessage2);
                requestMessageAppServiceCaller = mbCallerAppService.CreateApplicationServiceSendMessageRequest(callerToken, messageBytes);
                uint callerMessage2Id = requestMessageAppServiceCaller.Id;
                await clientCallerAppService.SendMessageAsync(requestMessageAppServiceCaller);

                string callerMessage3 = "Message #3 to callee.";
                messageBytes = Encoding.UTF8.GetBytes(callerMessage3);
                requestMessageAppServiceCaller = mbCallerAppService.CreateApplicationServiceSendMessageRequest(callerToken, messageBytes);
                uint callerMessage3Id = requestMessageAppServiceCaller.Id;
                await clientCallerAppService.SendMessageAsync(requestMessageAppServiceCaller);


                // Step 7 Acceptance
                bool step7Ok = true;

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


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

                SemVer receivedVersion = new SemVer(serverRequestAppServiceCallee.Request.SingleRequest.Version);
                bool   versionOk       = receivedVersion.Equals(SemVer.V100);

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

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

                bool receiveMessageOk1 = versionOk && typeOk && messageOk;


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


                // Receive message #2.
                serverRequestAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync();

                receivedVersion = new SemVer(serverRequestAppServiceCallee.Request.SingleRequest.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

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

                receivedMessage = Encoding.UTF8.GetString(serverRequestAppServiceCallee.Request.SingleRequest.ApplicationServiceReceiveMessageNotification.Message.ToByteArray());
                messageOk       = receivedMessage == callerMessage2;

                bool receiveMessageOk2 = versionOk && typeOk && messageOk;


                // ACK message #2.
                serverResponseAppServiceCallee = mbCalleeAppService.CreateApplicationServiceReceiveMessageNotificationResponse(serverRequestAppServiceCallee);
                await clientCalleeAppService.SendMessageAsync(serverResponseAppServiceCallee);


                // 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);


                await Task.Delay(3000);


                // Send ping request.
                byte[] payload = Encoding.UTF8.GetBytes("test");
                requestMessageAppServiceCallee = mbCalleeAppService.CreatePingRequest(payload);
                await clientCalleeAppService.SendMessageAsync(requestMessageAppServiceCallee);



                // Receive message #3.
                serverRequestAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync();

                receivedVersion = new SemVer(serverRequestAppServiceCallee.Request.SingleRequest.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

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

                receivedMessage = Encoding.UTF8.GetString(serverRequestAppServiceCallee.Request.SingleRequest.ApplicationServiceReceiveMessageNotification.Message.ToByteArray());
                messageOk       = receivedMessage == callerMessage3;

                bool receiveMessageOk3 = versionOk && typeOk && messageOk;


                // Read ping response.
                responseMessageAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync();

                idOk            = responseMessageAppServiceCallee.Id == requestMessageAppServiceCallee.Id;
                statusOk        = responseMessageAppServiceCallee.Response.Status == Status.Ok;
                receivedVersion = new SemVer(responseMessageAppServiceCallee.Response.SingleResponse.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);


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

                byte[] receivedPayload = responseMessageAppServiceCallee.Response.SingleResponse.Ping.Payload.ToByteArray();
                bool   payloadOk       = StructuralComparisons.StructuralComparer.Compare(receivedPayload, payload) == 0;

                bool pingOk = idOk && statusOk && versionOk && typeOk && payloadOk;


                // ACK message #2.
                serverResponseAppServiceCallee = mbCalleeAppService.CreateApplicationServiceReceiveMessageNotificationResponse(serverRequestAppServiceCallee);
                await clientCalleeAppService.SendMessageAsync(serverResponseAppServiceCallee);



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

                await Task.Delay(3000);


                // Step 8 Acceptance
                bool step8Ok = receiveMessageOk1 && receiveMessageOk2 && pingOk && receiveMessageOk3;

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



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

                idOk            = responseMessageAppServiceCaller.Id == callerMessage1Id;
                statusOk        = responseMessageAppServiceCaller.Response.Status == Status.Ok;
                receivedVersion = new SemVer(responseMessageAppServiceCaller.Response.SingleResponse.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

                bool receiveAck1Ok = idOk && statusOk && versionOk;



                // Receive ACK message #2.
                responseMessageAppServiceCaller = await clientCallerAppService.ReceiveMessageAsync();

                idOk            = responseMessageAppServiceCaller.Id == callerMessage2Id;
                statusOk        = responseMessageAppServiceCaller.Response.Status == Status.Ok;
                receivedVersion = new SemVer(responseMessageAppServiceCaller.Response.SingleResponse.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

                bool receiveAck2Ok = idOk && statusOk && versionOk;



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

                receivedVersion = new SemVer(serverRequestAppServiceCaller.Request.SingleRequest.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

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

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

                receiveMessageOk1 = versionOk && typeOk && messageOk;



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



                // Receive ACK message #3.
                responseMessageAppServiceCaller = await clientCallerAppService.ReceiveMessageAsync();

                idOk            = responseMessageAppServiceCaller.Id == callerMessage3Id;
                statusOk        = responseMessageAppServiceCaller.Response.Status == Status.Ok;
                receivedVersion = new SemVer(responseMessageAppServiceCaller.Response.SingleResponse.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

                bool receiveAck3Ok = idOk && statusOk && versionOk;



                // Receive message #2 from callee.
                serverRequestAppServiceCaller = await clientCallerAppService.ReceiveMessageAsync();

                receivedVersion = new SemVer(serverRequestAppServiceCaller.Request.SingleRequest.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

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

                receivedMessage = Encoding.UTF8.GetString(serverRequestAppServiceCaller.Request.SingleRequest.ApplicationServiceReceiveMessageNotification.Message.ToByteArray());
                messageOk       = receivedMessage == calleeMessage2;

                receiveMessageOk2 = versionOk && typeOk && messageOk;



                // ACK message #2 from callee.
                serverResponseAppServiceCaller = mbCallerAppService.CreateApplicationServiceReceiveMessageNotificationResponse(serverRequestAppServiceCaller);
                await clientCallerAppService.SendMessageAsync(serverResponseAppServiceCaller);


                // Step 9 Acceptance
                bool step9Ok = receiveAck1Ok && receiveAck2Ok && receiveMessageOk1 && receiveAck3Ok && receiveMessageOk2;

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



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

                // Receive ACK message #1.
                responseMessageAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync();

                idOk            = responseMessageAppServiceCallee.Id == calleeMessage1Id;
                statusOk        = responseMessageAppServiceCallee.Response.Status == Status.Ok;
                receivedVersion = new SemVer(responseMessageAppServiceCallee.Response.SingleResponse.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

                receiveAck1Ok = idOk && statusOk && versionOk;

                // Receive ACK message #2.
                responseMessageAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync();

                idOk            = responseMessageAppServiceCallee.Id == calleeMessage2Id;
                statusOk        = responseMessageAppServiceCallee.Response.Status == Status.Ok;
                receivedVersion = new SemVer(responseMessageAppServiceCallee.Response.SingleResponse.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

                receiveAck2Ok = idOk && statusOk && versionOk;


                // Step 10 Acceptance
                bool step10Ok = receiveAck1Ok && receiveAck2Ok;

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


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

                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);
        }
Example #18
0
        /// <summary>
        /// Implementation of the test itself.
        /// </summary>
        /// <returns>true if the test passes, false otherwise.</returns>
        public override async Task <bool> RunAsync()
        {
            IPAddress ServerIp          = (IPAddress)ArgumentValues["Server IP"];
            int       ClNonCustomerPort = (int)ArgumentValues["clNonCustomer Port"];
            int       ClCustomerPort    = (int)ArgumentValues["clCustomer Port"];

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

            bool res = false;

            Passed = false;

            ProtocolClient client1 = new ProtocolClient();
            ProtocolClient client2 = new ProtocolClient(0, SemVer.V100, client1.GetIdentityKeys());

            try
            {
                MessageBuilder mb1 = client1.MessageBuilder;

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

                bool establishHostingOk = await client1.EstablishHostingAsync();

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


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

                bool checkInOk = await client1.CheckInAsync();

                // Step 2 Acceptance
                bool step2Ok = checkInOk;


                // Step 3
                await client2.ConnectAsync(ServerIp, 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);
        }
Example #19
0
        /// <summary>
        /// Implementation of the test itself.
        /// </summary>
        /// <returns>true if the test passes, false otherwise.</returns>
        public override async Task <bool> RunAsync()
        {
            IPAddress ServerIp          = (IPAddress)ArgumentValues["Server IP"];
            int       ClNonCustomerPort = (int)ArgumentValues["clNonCustomer Port"];
            int       ClCustomerPort    = (int)ArgumentValues["clCustomer Port"];

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

            bool res = false;

            Passed = false;

            ProtocolClient client = new ProtocolClient();

            try
            {
                MessageBuilder mb = client.MessageBuilder;

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

                bool establishHostingOk = await client.EstablishHostingAsync();

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


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

                bool checkInOk = await client.CheckInAsync();

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

                Message responseMessage = await client.ReceiveMessageAsync();

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

                bool cancelHostingAgreementOk = idOk && statusOk;

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

                client.CloseConnection();

                // Step 3
                await client.ConnectAsync(ServerIp, 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(ServerIp, ClNonCustomerPort, true);

                establishHostingOk = await client.EstablishHostingAsync();

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



                // Step 5
                await client.ConnectAsync(ServerIp, 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);
        }
Example #20
0
        /// <summary>
        /// Implementation of the test itself.
        /// </summary>
        /// <returns>true if the test passes, false otherwise.</returns>
        public override async Task <bool> RunAsync()
        {
            IPAddress ServerIp    = (IPAddress)ArgumentValues["Server IP"];
            int       PrimaryPort = (int)ArgumentValues["primary Port"];

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

            bool res = false;

            Passed = false;

            ProtocolClient client = new ProtocolClient();

            try
            {
                MessageBuilder mb = client.MessageBuilder;

                // Step 1
                log.Trace("Step 1");
                // Get port list.
                await client.ConnectAsync(ServerIp, PrimaryPort, false);

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

                client.CloseConnection();

                await client.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool hostingOk = await client.EstablishHostingAsync("Test");

                client.CloseConnection();

                await client.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClCustomer], true);

                bool checkInOk = await client.CheckInAsync();

                bool step1Ok = listPortsOk && hostingOk && checkInOk;
                log.Trace("Step 1: {0}", step1Ok ? "PASSED" : "FAILED");



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

                string       validityString = DateTime.UtcNow.AddMonths(1).ToString("yyyy-MM-dd'T'HH:mm:ss.fffK", DateTimeFormatInfo.InvariantInfo);
                CanIpnsEntry ipnsRecord     = new CanIpnsEntry()
                {
                    Value        = ProtocolHelper.ByteArrayToByteString(Encoding.UTF8.GetBytes("/ipfs/QmaRvpLT4RgBDVY6cQKwqQGQNtbM31KSqh8TxvQgFoEUus")),
                    ValidityType = CanIpnsEntry.Types.ValidityType.Eol,
                    Validity     = ProtocolHelper.ByteArrayToByteString(Encoding.UTF8.GetBytes(validityString)),
                    Sequence     = 1,
                    Ttl          = 6000000000,
                };
                ipnsRecord.Signature = ProtocolHelper.ByteArrayToByteString(client.CreateIpnsRecordSignature(ipnsRecord));

                Message requestMessage = mb.CreateCanPublishIpnsRecordRequest(ipnsRecord);
                await client.SendMessageAsync(requestMessage);

                Message responseMessage = await client.ReceiveMessageAsync();

                bool idOk     = responseMessage.Id == requestMessage.Id;
                bool statusOk = (responseMessage.Response.Status == Status.ErrorNotFound) || ((responseMessage.Response.Status == Status.ErrorInvalidValue) && (responseMessage.Response.Details == "record.value"));
                bool canPublishIpnsRecordOk = idOk && statusOk;

                // Step 2 Acceptance
                bool step2Ok = canPublishIpnsRecordOk;

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



                // Step 3
                log.Trace("Step 3");
                byte[]             serverId   = Crypto.Sha256(client.ServerKey);
                List <CanKeyValue> clientData = new List <CanKeyValue>()
                {
                    new CanKeyValue()
                    {
                        Key = "key1", StringValue = "value 1"
                    },
                    new CanKeyValue()
                    {
                        Key = "key2", Uint32Value = 2
                    },
                    new CanKeyValue()
                    {
                        Key = "key3", BoolValue = true
                    },
                    new CanKeyValue()
                    {
                        Key = "key4", BinaryValue = ProtocolHelper.ByteArrayToByteString(new byte[] { 1, 2, 3 })
                    },
                };

                CanIdentityData identityData1 = new CanIdentityData()
                {
                    HostingServerId = ProtocolHelper.ByteArrayToByteString(serverId)
                };
                identityData1.KeyValueList.AddRange(clientData);

                requestMessage = mb.CreateCanStoreDataRequest(identityData1);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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

                byte[] objectHash1 = responseMessage.Response.ConversationResponse.CanStoreData.Hash.ToByteArray();


                string objectPath1 = client.CreateIpfsPathFromHash(objectHash1);
                log.Trace("Object path 1 is '{0}'.", objectPath1);

                requestMessage = mb.CreateCanPublishIpnsRecordRequest(null);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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


                // Step 3 Acceptance
                bool step3Ok = canStoreDataOk && canPublishIpnsRecordOk;

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



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


                validityString = DateTime.UtcNow.AddMonths(1).ToString("yyyy-MM-dd'T'HH:mm:ss.fffK", DateTimeFormatInfo.InvariantInfo);
                ipnsRecord     = new CanIpnsEntry()
                {
                    Value        = ProtocolHelper.ByteArrayToByteString(Encoding.UTF8.GetBytes("ipfabc")),
                    ValidityType = CanIpnsEntry.Types.ValidityType.Eol,
                    Validity     = ProtocolHelper.ByteArrayToByteString(Encoding.UTF8.GetBytes(validityString)),
                    Sequence     = 1,
                    Ttl          = 6000000000,
                };
                ipnsRecord.Signature = ProtocolHelper.ByteArrayToByteString(client.CreateIpnsRecordSignature(ipnsRecord));

                requestMessage = mb.CreateCanPublishIpnsRecordRequest(ipnsRecord);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk      = responseMessage.Id == requestMessage.Id;
                statusOk  = responseMessage.Response.Status == Status.ErrorInvalidValue;
                detailsOk = responseMessage.Response.Details == "record.value";
                canPublishIpnsRecordOk = idOk && statusOk && detailsOk;

                // Step 4 Acceptance
                bool step4Ok = canPublishIpnsRecordOk;

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


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

                validityString = DateTime.UtcNow.AddMonths(1).ToString("yyyy-MM-dd'T'HH:mm:ss.fffK", DateTimeFormatInfo.InvariantInfo);
                ipnsRecord     = new CanIpnsEntry()
                {
                    Value        = ProtocolHelper.ByteArrayToByteString(Encoding.UTF8.GetBytes(objectPath1)),
                    ValidityType = CanIpnsEntry.Types.ValidityType.Eol,
                    Validity     = ProtocolHelper.ByteArrayToByteString(Encoding.UTF8.GetBytes(validityString)),
                    Sequence     = 1,
                    Ttl          = 6000000000,
                };
                ipnsRecord.Signature = ProtocolHelper.ByteArrayToByteString(client.CreateIpnsRecordSignature(ipnsRecord));

                requestMessage = mb.CreateCanPublishIpnsRecordRequest(ipnsRecord);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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

                // Step 5 Acceptance
                bool step5Ok = canPublishIpnsRecordOk;

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



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

                validityString = DateTime.UtcNow.AddMonths(1).ToString("yyyy-MM-dd'T'HH:mm:ss.fffK", DateTimeFormatInfo.InvariantInfo);
                ipnsRecord     = new CanIpnsEntry()
                {
                    Value        = ProtocolHelper.ByteArrayToByteString(Encoding.UTF8.GetBytes(objectPath1)),
                    ValidityType = CanIpnsEntry.Types.ValidityType.Eol,
                    Validity     = ProtocolHelper.ByteArrayToByteString(Encoding.UTF8.GetBytes(validityString)),
                    Sequence     = 1,
                    Ttl          = 6000000000,
                };
                ipnsRecord.Signature = ProtocolHelper.ByteArrayToByteString(client.CreateIpnsRecordSignature(ipnsRecord));

                requestMessage = mb.CreateCanPublishIpnsRecordRequest(ipnsRecord);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk      = responseMessage.Id == requestMessage.Id;
                statusOk  = responseMessage.Response.Status == Status.ErrorRejected;
                detailsOk = !string.IsNullOrEmpty(responseMessage.Response.Details);
                canPublishIpnsRecordOk = idOk && statusOk && detailsOk;

                // Step 6 Acceptance
                bool step6Ok = canPublishIpnsRecordOk;

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


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

                validityString = DateTime.UtcNow.AddMonths(1).ToString("yyyy-MM-dd'T'HH:mm:ss.fffK", DateTimeFormatInfo.InvariantInfo);
                ipnsRecord     = new CanIpnsEntry()
                {
                    Value        = ProtocolHelper.ByteArrayToByteString(Encoding.UTF8.GetBytes(objectPath1)),
                    ValidityType = CanIpnsEntry.Types.ValidityType.Eol,
                    Validity     = ProtocolHelper.ByteArrayToByteString(Encoding.UTF8.GetBytes(validityString)),
                    Sequence     = 2,
                    Ttl          = 6000000000,
                };
                ipnsRecord.Signature = ProtocolHelper.ByteArrayToByteString(new byte[] { 0x40, 0x40, 0x40, 0x40, 0x40 });

                requestMessage = mb.CreateCanPublishIpnsRecordRequest(ipnsRecord);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk      = responseMessage.Id == requestMessage.Id;
                statusOk  = responseMessage.Response.Status == Status.ErrorRejected;
                detailsOk = !string.IsNullOrEmpty(responseMessage.Response.Details);
                canPublishIpnsRecordOk = idOk && statusOk && detailsOk;

                // Step 7 Acceptance
                bool step7Ok = canPublishIpnsRecordOk;

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



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


                requestMessage = mb.CreateCanStoreDataRequest(null);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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


                validityString = DateTime.UtcNow.AddMonths(1).ToString("yyyy-MM-dd'T'HH:mm:ss.fffK", DateTimeFormatInfo.InvariantInfo);
                ipnsRecord     = new CanIpnsEntry()
                {
                    Value        = ProtocolHelper.ByteArrayToByteString(Encoding.UTF8.GetBytes(objectPath1)),
                    ValidityType = CanIpnsEntry.Types.ValidityType.Eol,
                    Validity     = ProtocolHelper.ByteArrayToByteString(Encoding.UTF8.GetBytes(validityString)),
                    Sequence     = 3,
                    Ttl          = 6000000000,
                };
                ipnsRecord.Signature = ProtocolHelper.ByteArrayToByteString(client.CreateIpnsRecordSignature(ipnsRecord));

                requestMessage = mb.CreateCanPublishIpnsRecordRequest(ipnsRecord);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

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

                // Step 8 Acceptance
                bool step8Ok = canStoreDataOk && canPublishIpnsRecordOk;

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



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

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


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

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

            bool res = false;

            Passed = false;

            ProtocolClient client = new ProtocolClient();

            try
            {
                MessageBuilder mb = client.MessageBuilder;

                // Step 1
                log.Trace("Step 1");
                // Get port list.
                await client.ConnectAsync(ServerIp, PrimaryPort, false);

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

                client.CloseConnection();

                await client.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool hostingOk = await client.EstablishHostingAsync("Test");

                client.CloseConnection();

                await client.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClCustomer], true);

                bool checkInOk = await client.CheckInAsync();

                bool step1Ok = listPortsOk && hostingOk && checkInOk;
                log.Trace("Step 1: {0}", step1Ok ? "PASSED" : "FAILED");



                // Step 2
                log.Trace("Step 2");
                byte[] serverId = new byte[5] {
                    0x40, 0x40, 0x40, 0x40, 0x40
                };
                List <CanKeyValue> clientData = new List <CanKeyValue>()
                {
                    new CanKeyValue()
                    {
                        Key = "key1", StringValue = "value 1"
                    },
                    new CanKeyValue()
                    {
                        Key = "key2", Uint32Value = 2
                    },
                    new CanKeyValue()
                    {
                        Key = "key3", BoolValue = true
                    },
                    new CanKeyValue()
                    {
                        Key = "key4", BinaryValue = ProtocolHelper.ByteArrayToByteString(new byte[] { 1, 2, 3 })
                    },
                };

                CanIdentityData identityData1 = new CanIdentityData()
                {
                    HostingServerId = ProtocolHelper.ByteArrayToByteString(serverId)
                };
                identityData1.KeyValueList.AddRange(clientData);

                Message requestMessage = mb.CreateCanStoreDataRequest(identityData1);
                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 == "data.hostingServerId";

                // Step 2 Acceptance
                bool step2Ok = idOk && statusOk && detailsOk;

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


                Passed = step1Ok && step2Ok;

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


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

            log.Trace("(ServerIp:'{0}',ClNonCustomerPort:{1},ClCustomerPort:{2})", ServerIp, 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(ServerIp, ClNonCustomerPort, true);

                bool establishHostingOk = await client.EstablishHostingAsync();

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


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

                bool checkInOk = await client.CheckInAsync();

                Message requestMessage = mb.CreateUpdateProfileRequest(SemVer.V100, "Test Identity", null, new GpsLocation(1, 2), 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;
                SemVer receivedVersion = new SemVer(responseMessage.Response.SingleResponse.GetIdentityInformation.Version);
                bool   versionOk       = receivedVersion.Equals(SemVer.V100);

                bool nameOk      = responseMessage.Response.SingleResponse.GetIdentityInformation.Name == "Test Identity";
                bool extraDataOk = responseMessage.Response.SingleResponse.GetIdentityInformation.ExtraData == "";
                bool locationOk  = responseMessage.Response.SingleResponse.GetIdentityInformation.Latitude == 1 &&
                                   responseMessage.Response.SingleResponse.GetIdentityInformation.Longitude == 2;

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


                byte[] imageData = File.ReadAllBytes(string.Format("images{0}PS04006.jpg", Path.DirectorySeparatorChar));
                requestMessage = mb.CreateUpdateProfileRequest(null, "Test Identity Renamed", imageData, new GpsLocation(-1, -2), "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;
                receivedVersion = new SemVer(responseMessage.Response.SingleResponse.GetIdentityInformation.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

                nameOk      = responseMessage.Response.SingleResponse.GetIdentityInformation.Name == "Test Identity Renamed";
                extraDataOk = responseMessage.Response.SingleResponse.GetIdentityInformation.ExtraData == "a=b";
                locationOk  = responseMessage.Response.SingleResponse.GetIdentityInformation.Latitude == -1 &&
                              responseMessage.Response.SingleResponse.GetIdentityInformation.Longitude == -2;


                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 && versionOk && nameOk && extraDataOk && locationOk && profileImageOk && thumbnailImageOk;



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

                responseMessage = await client.ReceiveMessageAsync();

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

                bool updateProfileOk3 = 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;
                receivedVersion = new SemVer(responseMessage.Response.SingleResponse.GetIdentityInformation.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

                nameOk      = responseMessage.Response.SingleResponse.GetIdentityInformation.Name == "Test Identity Renamed";
                extraDataOk = responseMessage.Response.SingleResponse.GetIdentityInformation.ExtraData == "a=b";
                locationOk  = responseMessage.Response.SingleResponse.GetIdentityInformation.Latitude == -1 &&
                              responseMessage.Response.SingleResponse.GetIdentityInformation.Longitude == -2;


                receivedProfileImage   = responseMessage.Response.SingleResponse.GetIdentityInformation.ProfileImage.ToByteArray();
                profileImageOk         = receivedProfileImage.Length == 0;
                receivedThumbnailImage = responseMessage.Response.SingleResponse.GetIdentityInformation.ThumbnailImage.ToByteArray();
                thumbnailImageOk       = receivedThumbnailImage.Length == 0;

                bool getIdentityInfoOk3 = idOk && statusOk && isHostedOk && isOnlineOk && pubKeyOk && versionOk && nameOk && extraDataOk && locationOk && profileImageOk && thumbnailImageOk;



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


                Passed = step1Ok && step2Ok;

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

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

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

            bool res = false;

            Passed = false;

            ProtocolClient client = new ProtocolClient();

            try
            {
                MessageBuilder mb = client.MessageBuilder;

                // Step 1
                log.Trace("Step 1");
                await client.ConnectAsync(ServerIp, ClNonCustomerPort, true);

                bool establishHostingOk = await client.EstablishHostingAsync();

                // Step 1 Acceptance
                bool step1Ok = establishHostingOk;
                log.Trace("Step 1: {0}", step1Ok ? "PASSED" : "FAILED");

                client.CloseConnection();


                // Step 2
                log.Trace("Step 2");
                await client.ConnectAsync(ServerIp, ClCustomerPort, true);

                bool startConversationOk = await client.StartConversationAsync();

                Message requestMessage = mb.CreateCheckInRequest(client.Challenge);
                // Invalidate the signature.
                byte[] signature = requestMessage.Request.ConversationRequest.Signature.ToByteArray();
                byte[] sig32     = new byte[32];
                Array.Copy(signature, sig32, sig32.Length);
                requestMessage.Request.ConversationRequest.Signature = ProtocolHelper.ByteArrayToByteString(sig32);

                await client.SendMessageAsync(requestMessage);

                Message responseMessage = await client.ReceiveMessageAsync();

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

                // Step 2 Acceptance
                bool step2Ok = startConversationOk && checkInOk;
                log.Trace("Step 2: {0}", step2Ok ? "PASSED" : "FAILED");

                Passed = step1Ok && step2Ok;

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

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

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

            bool res = false;

            Passed = false;

            ProtocolClient clientPrimary   = new ProtocolClient();
            ProtocolClient clientSecondary = new ProtocolClient();

            try
            {
                MessageBuilder mbPrimary   = clientPrimary.MessageBuilder;
                MessageBuilder mbSecondary = clientSecondary.MessageBuilder;

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

                // Get port list.
                await clientPrimary.ConnectAsync(ServerIp, PrimaryPort, false);

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

                clientPrimary.CloseConnection();

                // Establish hosting agreement for primary client.
                await clientPrimary.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool establishHostingOk = await clientPrimary.EstablishHostingAsync("Primary");

                clientPrimary.CloseConnection();

                // Check in primary client.
                await clientPrimary.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClCustomer], true);

                bool checkInOk = await clientPrimary.CheckInAsync();

                bool primaryOk = establishHostingOk && checkInOk;

                // Establish hosting agreement for secondary client.
                await clientSecondary.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                establishHostingOk = await clientSecondary.EstablishHostingAsync("Primary");

                clientSecondary.CloseConnection();

                // Check in secondary client.
                await clientSecondary.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClCustomer], true);

                checkInOk = await clientSecondary.CheckInAsync();

                bool secondaryOk = establishHostingOk && checkInOk;

                // Create card issuers.
                CardIssuers = new List <ProtocolClient>();
                for (int i = 0; i < IssuerCount; i++)
                {
                    ProtocolClient profileClient = new ProtocolClient();
                    CardIssuers.Add(profileClient);
                }


                // Step 1 Acceptance
                bool step1Ok = listPortsOk && primaryOk && secondaryOk;

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



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

                SignedCards      = new List <SignedRelationshipCard>();
                CardApplications = new List <CardApplicationInformation>();

                // Just to make it easy to follow the test specification.
                ProtocolClient Identity1 = CardIssuers[0];
                ProtocolClient Identity2 = CardIssuers[1];
                ProtocolClient Identity3 = CardIssuers[2];
                ProtocolClient Identity4 = CardIssuers[3];
                ProtocolClient Identity5 = CardIssuers[4];

                log.Trace("Identity1 ID: {0}", Crypto.ToHex(Identity1.GetIdentityId()));
                log.Trace("Identity2 ID: {0}", Crypto.ToHex(Identity2.GetIdentityId()));
                log.Trace("Identity3 ID: {0}", Crypto.ToHex(Identity3.GetIdentityId()));
                log.Trace("Identity4 ID: {0}", Crypto.ToHex(Identity4.GetIdentityId()));
                log.Trace("Identity5 ID: {0}", Crypto.ToHex(Identity5.GetIdentityId()));


                byte[]   primaryPubKey            = clientPrimary.GetIdentityKeys().PublicKey;
                string   type                     = "Card Type A";
                DateTime validFrom                = ProtocolHelper.UnixTimestampMsToDateTime(1479220556000);
                DateTime validTo                  = ProtocolHelper.UnixTimestampMsToDateTime(2479220556000);
                SignedRelationshipCard signedCard = Identity1.IssueRelationshipCard(primaryPubKey, type, validFrom, validTo);
                SignedCards.Add(signedCard);

                byte[] applicationId = new byte[] { 1 };
                CardApplicationInformation cardApplication = clientPrimary.CreateRelationshipCardApplication(applicationId, signedCard);
                CardApplications.Add(cardApplication);

                Message requestMessage = mbPrimary.CreateAddRelatedIdentityRequest(cardApplication, signedCard);
                await clientPrimary.SendMessageAsync(requestMessage);

                Message responseMessage = await clientPrimary.ReceiveMessageAsync();

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

                bool req1Ok = idOk && statusOk;


                type       = "Card Type A";
                validFrom  = ProtocolHelper.UnixTimestampMsToDateTime(1479220556000);
                validTo    = ProtocolHelper.UnixTimestampMsToDateTime(1479220557000);
                signedCard = Identity1.IssueRelationshipCard(primaryPubKey, type, validFrom, validTo);
                SignedCards.Add(signedCard);

                applicationId   = new byte[] { 2 };
                cardApplication = clientPrimary.CreateRelationshipCardApplication(applicationId, signedCard);
                CardApplications.Add(cardApplication);

                requestMessage = mbPrimary.CreateAddRelatedIdentityRequest(cardApplication, signedCard);
                await clientPrimary.SendMessageAsync(requestMessage);

                responseMessage = await clientPrimary.ReceiveMessageAsync();

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

                bool req2Ok = idOk && statusOk;


                type       = "Card Type A";
                validFrom  = ProtocolHelper.UnixTimestampMsToDateTime(1479220556000);
                validTo    = ProtocolHelper.UnixTimestampMsToDateTime(2479220556000);
                signedCard = Identity2.IssueRelationshipCard(primaryPubKey, type, validFrom, validTo);
                SignedCards.Add(signedCard);

                applicationId   = new byte[] { 3 };
                cardApplication = clientPrimary.CreateRelationshipCardApplication(applicationId, signedCard);
                CardApplications.Add(cardApplication);

                requestMessage = mbPrimary.CreateAddRelatedIdentityRequest(cardApplication, signedCard);
                await clientPrimary.SendMessageAsync(requestMessage);

                responseMessage = await clientPrimary.ReceiveMessageAsync();

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

                bool req3Ok = idOk && statusOk;


                type       = "Card Type A";
                validFrom  = ProtocolHelper.UnixTimestampMsToDateTime(2479220555000);
                validTo    = ProtocolHelper.UnixTimestampMsToDateTime(2479220556000);
                signedCard = Identity2.IssueRelationshipCard(primaryPubKey, type, validFrom, validTo);
                SignedCards.Add(signedCard);

                applicationId   = new byte[] { 4 };
                cardApplication = clientPrimary.CreateRelationshipCardApplication(applicationId, signedCard);
                CardApplications.Add(cardApplication);

                requestMessage = mbPrimary.CreateAddRelatedIdentityRequest(cardApplication, signedCard);
                await clientPrimary.SendMessageAsync(requestMessage);

                responseMessage = await clientPrimary.ReceiveMessageAsync();

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

                bool req4Ok = idOk && statusOk;


                type       = "Card Type B";
                validFrom  = ProtocolHelper.UnixTimestampMsToDateTime(1479220556000);
                validTo    = ProtocolHelper.UnixTimestampMsToDateTime(2479220556000);
                signedCard = Identity3.IssueRelationshipCard(primaryPubKey, type, validFrom, validTo);
                SignedCards.Add(signedCard);

                applicationId   = new byte[] { 5 };
                cardApplication = clientPrimary.CreateRelationshipCardApplication(applicationId, signedCard);
                CardApplications.Add(cardApplication);

                requestMessage = mbPrimary.CreateAddRelatedIdentityRequest(cardApplication, signedCard);
                await clientPrimary.SendMessageAsync(requestMessage);

                responseMessage = await clientPrimary.ReceiveMessageAsync();

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

                bool req5Ok = idOk && statusOk;


                type       = "Card Type B";
                validFrom  = ProtocolHelper.UnixTimestampMsToDateTime(1479220556000);
                validTo    = ProtocolHelper.UnixTimestampMsToDateTime(2479220556000);
                signedCard = Identity4.IssueRelationshipCard(primaryPubKey, type, validFrom, validTo);
                SignedCards.Add(signedCard);

                applicationId   = new byte[] { 6 };
                cardApplication = clientPrimary.CreateRelationshipCardApplication(applicationId, signedCard);
                CardApplications.Add(cardApplication);

                requestMessage = mbPrimary.CreateAddRelatedIdentityRequest(cardApplication, signedCard);
                await clientPrimary.SendMessageAsync(requestMessage);

                responseMessage = await clientPrimary.ReceiveMessageAsync();

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

                bool req6Ok = idOk && statusOk;


                type       = "Card Type C";
                validFrom  = ProtocolHelper.UnixTimestampMsToDateTime(1479220556000);
                validTo    = ProtocolHelper.UnixTimestampMsToDateTime(2479220556000);
                signedCard = Identity4.IssueRelationshipCard(primaryPubKey, type, validFrom, validTo);
                SignedCards.Add(signedCard);

                applicationId   = new byte[] { 7 };
                cardApplication = clientPrimary.CreateRelationshipCardApplication(applicationId, signedCard);
                CardApplications.Add(cardApplication);

                requestMessage = mbPrimary.CreateAddRelatedIdentityRequest(cardApplication, signedCard);
                await clientPrimary.SendMessageAsync(requestMessage);

                responseMessage = await clientPrimary.ReceiveMessageAsync();

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

                bool req7Ok = idOk && statusOk;


                type       = "Card Type C";
                validFrom  = ProtocolHelper.UnixTimestampMsToDateTime(1479220556000);
                validTo    = ProtocolHelper.UnixTimestampMsToDateTime(2479220556000);
                signedCard = Identity4.IssueRelationshipCard(primaryPubKey, type, validFrom, validTo);
                SignedCards.Add(signedCard);

                applicationId   = new byte[] { 8 };
                cardApplication = clientPrimary.CreateRelationshipCardApplication(applicationId, signedCard);
                CardApplications.Add(cardApplication);

                requestMessage = mbPrimary.CreateAddRelatedIdentityRequest(cardApplication, signedCard);
                await clientPrimary.SendMessageAsync(requestMessage);

                responseMessage = await clientPrimary.ReceiveMessageAsync();

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

                bool req8Ok = idOk && statusOk;


                type       = "Other";
                validFrom  = ProtocolHelper.UnixTimestampMsToDateTime(1479220556000);
                validTo    = ProtocolHelper.UnixTimestampMsToDateTime(2479220556000);
                signedCard = Identity5.IssueRelationshipCard(primaryPubKey, type, validFrom, validTo);
                SignedCards.Add(signedCard);

                applicationId   = new byte[] { 9 };
                cardApplication = clientPrimary.CreateRelationshipCardApplication(applicationId, signedCard);
                CardApplications.Add(cardApplication);

                requestMessage = mbPrimary.CreateAddRelatedIdentityRequest(cardApplication, signedCard);
                await clientPrimary.SendMessageAsync(requestMessage);

                responseMessage = await clientPrimary.ReceiveMessageAsync();

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

                bool req9Ok = idOk && statusOk;


                // Step 2 Acceptance
                bool step2Ok = req1Ok && req2Ok && req3Ok && req4Ok && req5Ok && req6Ok && req7Ok && req8Ok && req9Ok;

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


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

                byte[] secondaryPubKey = clientSecondary.GetIdentityKeys().PublicKey;
                type       = "Card Type A";
                validFrom  = ProtocolHelper.UnixTimestampMsToDateTime(1479220556000);
                validTo    = ProtocolHelper.UnixTimestampMsToDateTime(2479220556000);
                signedCard = Identity1.IssueRelationshipCard(secondaryPubKey, type, validFrom, validTo);
                SignedCards.Add(signedCard);

                applicationId   = new byte[] { 1 };
                cardApplication = clientSecondary.CreateRelationshipCardApplication(applicationId, signedCard);
                CardApplications.Add(cardApplication);

                requestMessage = mbSecondary.CreateAddRelatedIdentityRequest(cardApplication, signedCard);
                await clientSecondary.SendMessageAsync(requestMessage);

                responseMessage = await clientSecondary.ReceiveMessageAsync();

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

                bool req10Ok = idOk && statusOk;


                // Step 3 Acceptance
                bool step3Ok = req10Ok;

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


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

                byte[] primaryClientId = clientPrimary.GetIdentityId();
                requestMessage = mbSecondary.CreateGetIdentityRelationshipsInformationRequest(primaryClientId, true, null, null);
                await clientSecondary.SendMessageAsync(requestMessage);

                responseMessage = await clientSecondary.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;
                SemVer receivedVersion = new SemVer(responseMessage.Response.SingleResponse.Version);
                bool   versionOk       = receivedVersion.Equals(SemVer.V100);

                HashSet <int> numberList = new HashSet <int>()
                {
                    1, 2, 3, 4, 5, 6, 7, 8, 9
                };
                bool relationshipsOk = CheckRelationships(numberList, responseMessage.Response.SingleResponse.GetIdentityRelationshipsInformation.Relationships);

                req1Ok = idOk && statusOk && versionOk && relationshipsOk;


                requestMessage = mbSecondary.CreateGetIdentityRelationshipsInformationRequest(primaryClientId, false, null, null);
                await clientSecondary.SendMessageAsync(requestMessage);

                responseMessage = await clientSecondary.ReceiveMessageAsync();

                idOk            = responseMessage.Id == requestMessage.Id;
                statusOk        = responseMessage.Response.Status == Status.Ok;
                receivedVersion = new SemVer(responseMessage.Response.SingleResponse.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

                numberList = new HashSet <int>()
                {
                    1, 3, 5, 6, 7, 8, 9
                };
                relationshipsOk = CheckRelationships(numberList, responseMessage.Response.SingleResponse.GetIdentityRelationshipsInformation.Relationships);

                req2Ok = idOk && statusOk && versionOk && relationshipsOk;


                requestMessage = mbSecondary.CreateGetIdentityRelationshipsInformationRequest(primaryClientId, true, "*", null);
                await clientSecondary.SendMessageAsync(requestMessage);

                responseMessage = await clientSecondary.ReceiveMessageAsync();

                idOk            = responseMessage.Id == requestMessage.Id;
                statusOk        = responseMessage.Response.Status == Status.Ok;
                receivedVersion = new SemVer(responseMessage.Response.SingleResponse.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

                numberList = new HashSet <int>()
                {
                    1, 2, 3, 4, 5, 6, 7, 8, 9
                };
                relationshipsOk = CheckRelationships(numberList, responseMessage.Response.SingleResponse.GetIdentityRelationshipsInformation.Relationships);

                req3Ok = idOk && statusOk && versionOk && relationshipsOk;


                requestMessage = mbSecondary.CreateGetIdentityRelationshipsInformationRequest(primaryClientId, true, "**", null);
                await clientSecondary.SendMessageAsync(requestMessage);

                responseMessage = await clientSecondary.ReceiveMessageAsync();

                idOk            = responseMessage.Id == requestMessage.Id;
                statusOk        = responseMessage.Response.Status == Status.Ok;
                receivedVersion = new SemVer(responseMessage.Response.SingleResponse.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

                numberList = new HashSet <int>()
                {
                    1, 2, 3, 4, 5, 6, 7, 8, 9
                };
                relationshipsOk = CheckRelationships(numberList, responseMessage.Response.SingleResponse.GetIdentityRelationshipsInformation.Relationships);

                req4Ok = idOk && statusOk && versionOk && relationshipsOk;


                requestMessage = mbSecondary.CreateGetIdentityRelationshipsInformationRequest(primaryClientId, true, "Card*", null);
                await clientSecondary.SendMessageAsync(requestMessage);

                responseMessage = await clientSecondary.ReceiveMessageAsync();

                idOk            = responseMessage.Id == requestMessage.Id;
                statusOk        = responseMessage.Response.Status == Status.Ok;
                receivedVersion = new SemVer(responseMessage.Response.SingleResponse.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

                numberList = new HashSet <int>()
                {
                    1, 2, 3, 4, 5, 6, 7, 8
                };
                relationshipsOk = CheckRelationships(numberList, responseMessage.Response.SingleResponse.GetIdentityRelationshipsInformation.Relationships);

                req5Ok = idOk && statusOk && versionOk && relationshipsOk;


                requestMessage = mbSecondary.CreateGetIdentityRelationshipsInformationRequest(primaryClientId, true, "*Type A", null);
                await clientSecondary.SendMessageAsync(requestMessage);

                responseMessage = await clientSecondary.ReceiveMessageAsync();

                idOk            = responseMessage.Id == requestMessage.Id;
                statusOk        = responseMessage.Response.Status == Status.Ok;
                receivedVersion = new SemVer(responseMessage.Response.SingleResponse.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

                numberList = new HashSet <int>()
                {
                    1, 2, 3, 4
                };
                relationshipsOk = CheckRelationships(numberList, responseMessage.Response.SingleResponse.GetIdentityRelationshipsInformation.Relationships);

                req6Ok = idOk && statusOk && versionOk && relationshipsOk;


                requestMessage = mbSecondary.CreateGetIdentityRelationshipsInformationRequest(primaryClientId, true, "*Type *", null);
                await clientSecondary.SendMessageAsync(requestMessage);

                responseMessage = await clientSecondary.ReceiveMessageAsync();

                idOk            = responseMessage.Id == requestMessage.Id;
                statusOk        = responseMessage.Response.Status == Status.Ok;
                receivedVersion = new SemVer(responseMessage.Response.SingleResponse.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

                numberList = new HashSet <int>()
                {
                    1, 2, 3, 4, 5, 6, 7, 8
                };
                relationshipsOk = CheckRelationships(numberList, responseMessage.Response.SingleResponse.GetIdentityRelationshipsInformation.Relationships);

                req7Ok = idOk && statusOk && versionOk && relationshipsOk;


                requestMessage = mbSecondary.CreateGetIdentityRelationshipsInformationRequest(primaryClientId, true, null, Identity1.GetIdentityId());
                await clientSecondary.SendMessageAsync(requestMessage);

                responseMessage = await clientSecondary.ReceiveMessageAsync();

                idOk            = responseMessage.Id == requestMessage.Id;
                statusOk        = responseMessage.Response.Status == Status.Ok;
                receivedVersion = new SemVer(responseMessage.Response.SingleResponse.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

                numberList = new HashSet <int>()
                {
                    1, 2
                };
                relationshipsOk = CheckRelationships(numberList, responseMessage.Response.SingleResponse.GetIdentityRelationshipsInformation.Relationships);

                req8Ok = idOk && statusOk && versionOk && relationshipsOk;


                requestMessage = mbSecondary.CreateGetIdentityRelationshipsInformationRequest(primaryClientId, true, "*C", Identity4.GetIdentityId());
                await clientSecondary.SendMessageAsync(requestMessage);

                responseMessage = await clientSecondary.ReceiveMessageAsync();

                idOk            = responseMessage.Id == requestMessage.Id;
                statusOk        = responseMessage.Response.Status == Status.Ok;
                receivedVersion = new SemVer(responseMessage.Response.SingleResponse.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

                numberList = new HashSet <int>()
                {
                    7, 8
                };
                relationshipsOk = CheckRelationships(numberList, responseMessage.Response.SingleResponse.GetIdentityRelationshipsInformation.Relationships);

                req9Ok = idOk && statusOk && versionOk && relationshipsOk;


                // Step 4 Acceptance
                bool step4Ok = req1Ok && req2Ok && req3Ok && req4Ok && req5Ok && req6Ok && req7Ok && req8Ok && req9Ok;

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



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

                applicationId  = new byte[] { 2 };
                requestMessage = mbPrimary.CreateRemoveRelatedIdentityRequest(applicationId);
                await clientPrimary.SendMessageAsync(requestMessage);

                responseMessage = await clientPrimary.ReceiveMessageAsync();

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

                bool removeRelation1Ok = idOk && statusOk;

                applicationId  = new byte[] { 4 };
                requestMessage = mbPrimary.CreateRemoveRelatedIdentityRequest(applicationId);
                await clientPrimary.SendMessageAsync(requestMessage);

                responseMessage = await clientPrimary.ReceiveMessageAsync();

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

                bool removeRelation2Ok = idOk && statusOk;



                requestMessage = mbPrimary.CreateGetIdentityRelationshipsInformationRequest(primaryClientId, true, "*Type a*", null);
                await clientPrimary.SendMessageAsync(requestMessage);

                responseMessage = await clientPrimary.ReceiveMessageAsync();

                idOk            = responseMessage.Id == requestMessage.Id;
                statusOk        = responseMessage.Response.Status == Status.Ok;
                receivedVersion = new SemVer(responseMessage.Response.SingleResponse.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

                numberList = new HashSet <int>()
                {
                    1, 3
                };
                relationshipsOk = CheckRelationships(numberList, responseMessage.Response.SingleResponse.GetIdentityRelationshipsInformation.Relationships);

                req1Ok = idOk && statusOk && versionOk && relationshipsOk;



                byte[] partId = new byte[10];
                Array.Copy(primaryClientId, partId, partId.Length);
                requestMessage = mbPrimary.CreateGetIdentityRelationshipsInformationRequest(partId, true, "*Type a*", null);
                await clientPrimary.SendMessageAsync(requestMessage);

                responseMessage = await clientPrimary.ReceiveMessageAsync();

                idOk            = responseMessage.Id == requestMessage.Id;
                statusOk        = responseMessage.Response.Status == Status.Ok;
                receivedVersion = new SemVer(responseMessage.Response.SingleResponse.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

                relationshipsOk = responseMessage.Response.SingleResponse.GetIdentityRelationshipsInformation.Relationships.Count == 0;

                req1Ok = idOk && statusOk && versionOk && relationshipsOk;



                // Step 5 Acceptance
                bool step5Ok = removeRelation1Ok && removeRelation2Ok && req1Ok && req2Ok;

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


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

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

            if (CardIssuers != null)
            {
                for (int i = 0; i < IssuerCount; i++)
                {
                    if (CardIssuers[i] != null)
                    {
                        CardIssuers[i].Dispose();
                    }
                }
            }


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

            log.Trace("(ServerIp:'{0}',ClNonCustomerPort:{1})", ServerIp, 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(ServerIp, ClNonCustomerPort, true);

                bool hostingOk = await client1.EstablishHostingAsync();

                client1.CloseConnection();

                // Step 1 Acceptance
                bool step1Ok = hostingOk;


                // Step 2
                await client2.ConnectAsync(ServerIp, 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);
        }
Example #26
0
        /// <summary>
        /// Implementation of the test itself.
        /// </summary>
        /// <returns>true if the test passes, false otherwise.</returns>
        public override async Task <bool> RunAsync()
        {
            IPAddress ServerIp    = (IPAddress)ArgumentValues["Server IP"];
            int       PrimaryPort = (int)ArgumentValues["primary Port"];

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

            bool res = false;

            Passed = false;

            ProtocolClient clientCallee           = new ProtocolClient();
            ProtocolClient clientCalleeAppService = new ProtocolClient(0, SemVer.V100, clientCallee.GetIdentityKeys());

            ProtocolClient clientCaller           = new ProtocolClient();
            ProtocolClient clientCallerAppService = new ProtocolClient(0, SemVer.V100, 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(ServerIp, PrimaryPort, false);

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

                clientCallee.CloseConnection();


                // Establish hosting agreement for identity 1.
                await clientCallee.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool establishHostingOk = await clientCallee.EstablishHostingAsync();

                clientCallee.CloseConnection();


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

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

                bool checkInOk = await clientCallee.CheckInAsync();

                bool initializeProfileOk = await clientCallee.InitializeProfileAsync("Test Identity", null, new GpsLocation(0, 0), 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 && establishHostingOk && checkInOk && initializeProfileOk && addAppServiceOk;

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



                // Step 2
                log.Trace("Step 2");
                await clientCaller.ConnectAsync(ServerIp, (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);
        }
Example #27
0
        /// <summary>
        /// Implementation of the test itself.
        /// </summary>
        /// <returns>true if the test passes, false otherwise.</returns>
        public override async Task <bool> RunAsync()
        {
            IPAddress ServerIp    = (IPAddress)ArgumentValues["Server IP"];
            int       PrimaryPort = (int)ArgumentValues["primary Port"];

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

            bool res = false;

            Passed = false;

            ProtocolClient client = new ProtocolClient();

            try
            {
                MessageBuilder mb = client.MessageBuilder;

                // Step 1
                log.Trace("Step 1");
                // Get port list.
                await client.ConnectAsync(ServerIp, PrimaryPort, false);

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

                client.CloseConnection();

                // Radius generation.
                R2 = (uint)Rng.Next(R2Min, R2Max);
                R1 = (uint)Rng.Next(R1Min, (int)(R1R2RatioMax * R2));
                R3 = (uint)Rng.Next((int)(R3R2RatioMax * R2), R3Max);
                log.Trace("R1: {0,8} m", R1);
                log.Trace("R2: {0,8} m", R2);
                log.Trace("R3: {0,8} m", R3);

                // Location generation
                for (int i = 0; i < LocationCount; i++)
                {
                    if (PredefinedLocations.Count > i)
                    {
                        GeneratedLocations.Add(GenerateLocation(PredefinedLocations[i], R2));
                    }
                    else
                    {
                        int lat = Rng.Next((int)(GpsLocation.LatitudeMin * GpsLocation.LocationTypeFactor), (int)(GpsLocation.LatitudeMax * GpsLocation.LocationTypeFactor) + 1);
                        int lon = Rng.Next((int)(GpsLocation.LongitudeMin * GpsLocation.LocationTypeFactor) + 1, (int)(GpsLocation.LongitudeMax * GpsLocation.LocationTypeFactor) + 1);
                        GeneratedLocations.Add(new GpsLocation(lat, lon));
                    }
                }

                log.Trace("Generated locations:");
                for (int i = 0; i < LocationCount; i++)
                {
                    log.Trace(" #{0:00}: {1:US}", i, GeneratedLocations[i]);
                }


                bool profileInitializationOk = true;

                uint[] rads = new uint[] { R1, R2, R3 };
                for (int locIndex = 0; locIndex < LocationCount; locIndex++)
                {
                    for (uint radIndex = 0; radIndex < rads.Length; radIndex++)
                    {
                        for (int idIndex = 0; idIndex < RadiusIdentityCount; idIndex++)
                        {
                            GpsLocation basePoint = GeneratedLocations[locIndex];
                            uint        radius    = rads[radIndex];
                            GpsLocation location  = GenerateLocation(basePoint, radius);
                            ProfileLocations.Add(location);

                            string name = string.Format("{0:00}-{1:00}-{2:00} [{3:US}]", locIndex, idIndex, radIndex, location);
                            ProfileNames.Add(name);

                            ProtocolClient profileClient = new ProtocolClient();

                            await profileClient.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                            bool establishHostingOk = await profileClient.EstablishHostingAsync("test");

                            profileClient.CloseConnection();

                            await profileClient.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClCustomer], true);

                            bool checkInOk = await profileClient.CheckInAsync();

                            bool initializeProfileOk = await profileClient.InitializeProfileAsync(name, null, location, null);

                            profileInitializationOk = establishHostingOk && checkInOk && initializeProfileOk;
                            profileClient.Dispose();

                            if (!profileInitializationOk)
                            {
                                break;
                            }
                        }
                    }
                }


                log.Trace("Generated profile names:");
                for (int i = 0; i < ProfileNames.Count; i++)
                {
                    log.Trace(" {0}", ProfileNames[i]);
                }


                // Step 1 Acceptance
                bool step1Ok = listPortsOk && profileInitializationOk;

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


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

                // Start conversation.
                await client.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool startConversationOk = await client.StartConversationAsync();

                // Search all profiles.
                Message requestMessage = mb.CreateProfileSearchRequest(null, null, null, null, 0, 1000, 1000, false, false);
                await client.SendMessageAsync(requestMessage);

                Message responseMessage = await client.ReceiveMessageAsync();

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


                bool totalRecordCountOk       = responseMessage.Response.ConversationResponse.ProfileSearch.TotalRecordCount == ProfileNames.Count;
                bool maxResponseRecordCountOk = responseMessage.Response.ConversationResponse.ProfileSearch.MaxResponseRecordCount == 1000;
                bool profilesCountOk          = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count == ProfileNames.Count;

                bool queryRespOk = idOk && statusOk && totalRecordCountOk && maxResponseRecordCountOk && profilesCountOk;
                bool resultsOk   = CompareResults(ProfileNames, responseMessage.Response.ConversationResponse.ProfileSearch.Profiles);

                bool query1Ok = queryRespOk && resultsOk;

                bool queriesOk = true;
                // Search queries around target locations.
                for (int locIndex = 0; locIndex < LocationCount; locIndex++)
                {
                    for (uint radIndex = 0; radIndex < rads.Length + 1; radIndex++)
                    {
                        uint        radius         = radIndex < rads.Length ? rads[radIndex] : (uint)Rng.Next(1000000, 10000000);
                        GpsLocation targetLocation = GeneratedLocations[locIndex];
                        requestMessage = mb.CreateProfileSearchRequest(null, null, null, targetLocation, radius, 1000, 1000, false, false);
                        await client.SendMessageAsync(requestMessage);

                        responseMessage = await client.ReceiveMessageAsync();

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

                        List <string> expectedNames = GetProfileNamesInLocation(targetLocation, radius);
                        totalRecordCountOk       = responseMessage.Response.ConversationResponse.ProfileSearch.TotalRecordCount == expectedNames.Count;
                        maxResponseRecordCountOk = responseMessage.Response.ConversationResponse.ProfileSearch.MaxResponseRecordCount == 1000;
                        profilesCountOk          = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count == expectedNames.Count;

                        queryRespOk = idOk && statusOk && totalRecordCountOk && maxResponseRecordCountOk && profilesCountOk;
                        resultsOk   = CompareResults(expectedNames, responseMessage.Response.ConversationResponse.ProfileSearch.Profiles);

                        queriesOk = queryRespOk && resultsOk;
                        if (!queriesOk)
                        {
                            log.Trace("Search query location {0} with radius {1} should produce {2} profiles, but produced {3} profiles.", targetLocation, radius, expectedNames.Count, responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Count);
                            log.Trace("Expected names list:");
                            foreach (string name in expectedNames)
                            {
                                log.Trace("  {0}", name);
                            }

                            List <string> resultNames = responseMessage.Response.ConversationResponse.ProfileSearch.Profiles.Select(r => r.Name).OrderBy(r => r).ToList();
                            log.Trace("Query result names list:");
                            foreach (string name in resultNames)
                            {
                                log.Trace("  {0}", name);
                            }
                            break;
                        }

                        log.Trace("Search query location {0} with radius {1} produced {2} correct profiles.", targetLocation, radius, expectedNames.Count);
                    }

                    if (!queriesOk)
                    {
                        break;
                    }
                }

                // Step 2 Acceptance
                bool step2Ok = startConversationOk && query1Ok && queriesOk;

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



                Passed = step1Ok && step2Ok;

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

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

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

            bool res = false;

            Passed = false;

            ProtocolClient client = new ProtocolClient();

            try
            {
                MessageBuilder mb = client.MessageBuilder;

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

                bool establishHostingOk = await client.EstablishHostingAsync();

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

                // Step 2
                await client.ConnectAsync(ServerIp, 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);
        }
Example #29
0
        /// <summary>
        /// Implementation of the test itself.
        /// </summary>
        /// <returns>true if the test passes, false otherwise.</returns>
        public override async Task <bool> RunAsync()
        {
            IPAddress ServerIp    = (IPAddress)ArgumentValues["Server IP"];
            int       PrimaryPort = (int)ArgumentValues["primary Port"];

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

            bool res = false;

            Passed = false;

            ProtocolClient clientCallee           = new ProtocolClient();
            ProtocolClient clientCalleeAppService = new ProtocolClient(0, SemVer.V100, clientCallee.GetIdentityKeys());

            ProtocolClient clientCaller1           = new ProtocolClient();
            ProtocolClient clientCaller1AppService = new ProtocolClient(0, SemVer.V100, clientCaller1.GetIdentityKeys());

            ProtocolClient clientCaller2           = new ProtocolClient();
            ProtocolClient clientCaller2AppService = new ProtocolClient(0, SemVer.V100, clientCaller2.GetIdentityKeys());

            try
            {
                MessageBuilder mbCallee           = clientCallee.MessageBuilder;
                MessageBuilder mbCalleeAppService = clientCalleeAppService.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(ServerIp, PrimaryPort, false);

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

                clientCallee.CloseConnection();


                // Establish hosting agreement for identity 1.
                await clientCallee.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool establishHostingOk = await clientCallee.EstablishHostingAsync();

                clientCallee.CloseConnection();


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

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

                bool checkInOk = await clientCallee.CheckInAsync();

                bool initializeProfileOk = await clientCallee.InitializeProfileAsync("Test Identity", null, new GpsLocation(0, 0), 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 && establishHostingOk && checkInOk && initializeProfileOk && addAppServiceOk;

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



                // Step 2
                log.Trace("Step 2");
                await clientCaller1.ConnectAsync(ServerIp, (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(ServerIp, (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 serverRequestMessage = await clientCallee.ReceiveMessageAsync();

                // What we received now can actually be either notification about caller1 or caller2, we do not know.
                // So we have to check, which one is it before we proceed.
                byte[] receivedPubKey = serverRequestMessage.Request.ConversationRequest.IncomingCallNotification.CallerPublicKey.ToByteArray();
                bool   isCaller1      = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, pubKeyCaller1) == 0;
                bool   isCaller2      = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, pubKeyCaller2) == 0;
                bool   pubKeyOk       = isCaller1 || isCaller2;
                bool   serviceNameOk  = serverRequestMessage.Request.ConversationRequest.IncomingCallNotification.ServiceName == serviceName;

                bool incomingCallNotificationOk1 = pubKeyOk && serviceNameOk;

                byte[] calleeToken1 = null;
                byte[] calleeToken2 = null;
                if (isCaller1)
                {
                    calleeToken1 = serverRequestMessage.Request.ConversationRequest.IncomingCallNotification.CalleeToken.ToByteArray();
                }
                else
                {
                    calleeToken2 = serverRequestMessage.Request.ConversationRequest.IncomingCallNotification.CalleeToken.ToByteArray();
                }

                Message serverResponseMessage = mbCallee.CreateIncomingCallNotificationResponse(serverRequestMessage);
                await clientCallee.SendMessageAsync(serverResponseMessage);



                serverRequestMessage = await clientCallee.ReceiveMessageAsync();

                // This time, it has to be the other caller
                receivedPubKey = serverRequestMessage.Request.ConversationRequest.IncomingCallNotification.CallerPublicKey.ToByteArray();
                if (isCaller1)
                {
                    pubKeyOk = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, pubKeyCaller2) == 0;
                }
                else
                {
                    pubKeyOk = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, pubKeyCaller1) == 0;
                }
                serviceNameOk = serverRequestMessage.Request.ConversationRequest.IncomingCallNotification.ServiceName == serviceName;

                bool incomingCallNotificationOk2 = pubKeyOk && serviceNameOk;

                if (isCaller1)
                {
                    calleeToken2 = serverRequestMessage.Request.ConversationRequest.IncomingCallNotification.CalleeToken.ToByteArray();
                }
                else
                {
                    calleeToken1 = serverRequestMessage.Request.ConversationRequest.IncomingCallNotification.CalleeToken.ToByteArray();
                }

                serverResponseMessage = mbCallee.CreateIncomingCallNotificationResponse(serverRequestMessage);
                await clientCallee.SendMessageAsync(serverResponseMessage);



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

                Message requestMessageAppServiceCallee = mbCalleeAppService.CreateApplicationServiceSendMessageRequest(calleeToken1, null);
                await clientCalleeAppService.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[] callerToken = responseMessage.Response.ConversationResponse.CallIdentityApplicationService.CallerToken.ToByteArray();

                bool callIdentityOk = idOk && statusOk;

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

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

                Message responseMessageAppServiceCaller = await clientCaller1AppService.ReceiveMessageAsync();

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

                bool initAppServiceMessageOk = idOk && statusOk;


                // 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 caller1Message1 = "Message #1 to callee.";
                byte[] messageBytes    = Encoding.UTF8.GetBytes(caller1Message1);
                requestMessageAppServiceCaller = mbCaller1AppService.CreateApplicationServiceSendMessageRequest(callerToken, 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 serverRequestAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync();

                SemVer receivedVersion = new SemVer(serverRequestAppServiceCallee.Request.SingleRequest.Version);
                bool   versionOk       = receivedVersion.Equals(SemVer.V100);

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

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

                bool receiveMessageOk = versionOk && typeOk && messageOk;


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



                // Send second intialization message
                await Task.Delay(3000);

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

                Message responseAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync();

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

                bool secondInitOk = idOk && statusOk;


                // Step 7 Acceptance
                bool step7Ok = secondInitOk;

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


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

                // Receive init message response.
                bool initMessageOk = false;
                bool disconnectOk  = false;
                try
                {
                    Message initMessageResponseAppServiceCaller2 = await clientCaller2AppService.ReceiveMessageAsync();

                    idOk     = initMessageResponseAppServiceCaller2.Id == initMessageCaller2Id;
                    statusOk = initMessageResponseAppServiceCaller2.Response.Status == Status.ErrorNotFound;

                    initMessageOk = idOk && statusOk;
                }
                catch
                {
                    log.Trace("Expected exception occurred.");
                    disconnectOk = true;
                }

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

                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 = new SemVer(responseMessageAppServiceCaller.Response.SingleResponse.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

                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();
            clientCalleeAppService.Dispose();
            clientCaller1.Dispose();
            clientCaller1AppService.Dispose();
            clientCaller2.Dispose();
            clientCaller2AppService.Dispose();

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