public async Task <IActionResult> Tap([FromBody] TapDto dto)
        {
            var card = _cardManager.FindByIdAsync(dto.CardNumber);

            if (card == null)
            {
                return(NotFound("please register your card"));
            }
            await _tokenManager.InvalidateRefreshToken(dto.CardNumber);

            return(Ok("logged out successfully"));
        }
示例#2
0
        public async Task UserTaps_WithUnregisteredCard_ReturnsUnauthorised()
        {
            // Arrange
            var          subject = GetSubject();
            IdentityCard card    = _identityCardBuilder.GenericIdentityCard().Build();
            var          tapDto  = new TapDto()
            {
                CardNumber = card.Id
            };

            // Act
            var result = await subject.Tap(tapDto);

            // Assert
            Assert.NotNull(result);
            Assert.Equal(typeof(OkObjectResult), result.GetType());
            _mockTokenManager.Verify(x => x.InvalidateRefreshToken(card.Id));
        }
        public async Task Post_tap_unauthorised()
        {
            // Arrange
            var client = _factory.CreateClient();
            var dto    = new TapDto()
            {
                CardNumber = "1234ewqs6789oiuy"
            };
            var json        = JsonConvert.SerializeObject(dto);
            var buffer      = System.Text.Encoding.UTF8.GetBytes(json);
            var byteContent = new ByteArrayContent(buffer);

            // Act
            var response = await client.PostAsync("/authentication/tap", byteContent);

            // Assert
            Assert.True(response.StatusCode == HttpStatusCode.Unauthorized);
        }
示例#4
0
        public async Task UserTaps_WithLoggedinUser_InvalidatesRefreshTokenReturnsOk()
        {
            // Arrange
            var          subject = GetSubject();
            IdentityCard card    = _identityCardBuilder.GenericIdentityCard().Build();

            _mockCardManager.Setup(x => x.FindByIdAsync(card.Id)).ReturnsAsync(card);
            var tapDto = new TapDto()
            {
                CardNumber = card.Id
            };

            // Act
            var result = await subject.Tap(tapDto);

            // Assert
            Assert.NotNull(result);
            Assert.Equal(typeof(OkObjectResult), result.GetType());
            _mockTokenManager.Verify(x => x.InvalidateRefreshToken(card.Id));
        }