示例#1
0
        public async Task SignAsync_WithRequirements__ShouldPostJsonPayload_WithRequirements()
        {
            // Arrange

            // Act
            await _bankIdApiClient.SignAsync(new SignRequest("1.1.1.1", "userVisibleData", Encoding.UTF8.GetBytes("userNonVisibleData"), "201801012392", new Requirement(new List <string> {
                "req1", "req2"
            }, true, true)));

            // Assert
            var request       = _messageHandlerMock.GetFirstArgumentOfFirstInvocation <HttpMessageHandler, HttpRequestMessage>();
            var contentString = await request.Content.ReadAsStringAsync();

            JsonTests.AssertProperty(contentString, "endUserIp", "1.1.1.1");
            JsonTests.AssertProperty(contentString, "personalNumber", "201801012392");
            JsonTests.AssertSubProperty(contentString, "requirement", "allowFingerprint", true);
            JsonTests.AssertSubProperty(contentString, "requirement", "certificatePolicies", new List <string> {
                "req1", "req2"
            });
            JsonTests.AssertSubProperty(contentString, "requirement", "tokenStartRequired", true);
            JsonTests.AssertProperty(contentString, "userVisibleData", "dXNlclZpc2libGVEYXRh");
            JsonTests.AssertProperty(contentString, "userNonVisibleData", "dXNlck5vblZpc2libGVEYXRh");
            JsonTests.AssertOnlyProperties(contentString, new[]
            {
                "endUserIp",
                "personalNumber",
                "requirement",
                "userVisibleData",
                "userNonVisibleData"
            });
        }
示例#2
0
        public async Task SignAsync_WithUserVisibleDataFormat__ShouldPostToBankIdSign_WithJsonPayload()
        {
            // Arrange

            // Act
            await _bankIdApiClient.SignAsync(new SignRequest("1.1.1.1", "userVisibleData", "userVisibleDataFormat", new byte[1]));

            // Assert
            var request       = _messageHandlerMock.GetFirstArgumentOfFirstInvocation <HttpMessageHandler, HttpRequestMessage>();
            var contentString = await request.Content.ReadAsStringAsync();

            JsonTests.AssertProperty(contentString, "endUserIp", "1.1.1.1");
            JsonTests.AssertPropertyIsEmptyObject(contentString, "requirement");
            JsonTests.AssertProperty(contentString, "userVisibleData", "dXNlclZpc2libGVEYXRh");
            JsonTests.AssertProperty(contentString, "userVisibleDataFormat", "userVisibleDataFormat");
            JsonTests.AssertProperty(contentString, "userNonVisibleData", "AA==");
            JsonTests.AssertOnlyProperties(contentString, new[]
            {
                "endUserIp",
                "requirement",
                "userVisibleData",
                "userVisibleDataFormat",
                "userNonVisibleData"
            });
        }
示例#3
0
        public async Task AuthAsync_WithAuthRequest__ShouldHaveUserData()
        {
            //Arrange
            byte[] userNonVisibleData = Encoding.ASCII.GetBytes("Hello");
            string asBase64           = Convert.ToBase64String(userNonVisibleData);

            //Act
            await _bankIdApiClient.AuthAsync(new AuthRequest("1.1.1.1", null, null, "Hello", userNonVisibleData, "simpleMarkdownV1"));

            //Assert
            var request       = _messageHandlerMock.GetFirstArgumentOfFirstInvocation <HttpMessageHandler, HttpRequestMessage>();
            var contentString = await request.Content.ReadAsStringAsync();

            JsonTests.AssertProperty(contentString, "endUserIp", "1.1.1.1");
            JsonTests.AssertPropertyIsEmptyObject(contentString, "requirement");
            JsonTests.AssertProperty(contentString, "userVisibleData", asBase64);
            JsonTests.AssertProperty(contentString, "userNonVisibleData", asBase64);
            JsonTests.AssertProperty(contentString, "userVisibleDataFormat", "simpleMarkdownV1");
            JsonTests.AssertOnlyProperties(contentString, new[]
            {
                "endUserIp",
                "requirement",
                "userVisibleData",
                "userNonVisibleData",
                "userVisibleDataFormat"
            });
        }
示例#4
0
        public async Task CancelAsync_WithOrderRef__ShouldPostJsonPayload_WithOrderRef()
        {
            // Arrange

            // Act
            await _bankIdApiClient.CancelAsync(new CancelRequest("abc123"));

            // Assert
            var request       = _messageHandlerMock.GetFirstArgumentOfFirstInvocation <HttpMessageHandler, HttpRequestMessage>();
            var contentString = await request.Content.ReadAsStringAsync();

            JsonTests.AssertProperty(contentString, "orderRef", "abc123");
            JsonTests.AssertOnlyProperties(contentString, new[]
            {
                "orderRef"
            });
        }
示例#5
0
        public async Task AuthAsync_WithEndUserIp__ShouldPostJsonPayload_WithEndUserIp_AndNoPersonalNumber_AndRequirementAsEmptyObject()
        {
            // Arrange

            // Act
            await _bankIdApiClient.AuthAsync(new AuthRequest("1.1.1.1"));

            // Assert
            var request       = _messageHandlerMock.GetFirstArgumentOfFirstInvocation <HttpMessageHandler, HttpRequestMessage>();
            var contentString = await request.Content.ReadAsStringAsync();

            JsonTests.AssertProperty(contentString, "endUserIp", "1.1.1.1");
            JsonTests.AssertPropertyIsEmptyObject(contentString, "requirement");
            JsonTests.AssertOnlyProperties(contentString, new[]
            {
                "endUserIp",
                "requirement"
            });
        }
示例#6
0
        public async Task SignAsync_WithEndUserIp_AndPin__ShouldPostJsonPayload_WithEndUserIp_AndPersonalNumber_AndUserVisibleData_AndNoRequirements()
        {
            // Arrange

            // Act
            await _bankIdApiClient.SignAsync(new SignRequest("1.1.1.1", "userVisibleData", null, "201801012392"));

            // Assert
            var request       = _messageHandlerMock.GetFirstArgumentOfFirstInvocation <HttpMessageHandler, HttpRequestMessage>();
            var contentString = await request.Content.ReadAsStringAsync();

            JsonTests.AssertProperty(contentString, "endUserIp", "1.1.1.1");
            JsonTests.AssertProperty(contentString, "personalNumber", "201801012392");
            JsonTests.AssertPropertyIsEmptyObject(contentString, "requirement");
            JsonTests.AssertProperty(contentString, "userVisibleData", "dXNlclZpc2libGVEYXRh");
            JsonTests.AssertOnlyProperties(contentString, new[]
            {
                "endUserIp",
                "personalNumber",
                "requirement",
                "userVisibleData"
            });
        }