public async Task SigninFailureReturnsNullAndLogsTheIssue()
        {
            // arrange
            var          loggerMock   = LoggerFixture.SetupLogCatcher();
            const string tokenName    = "Test Token";
            var          refreshToken = Guid.NewGuid().ToString();
            var          fixture      = new TokenManagerFixture();
            await fixture.SetupServerDataAsync(tokenName, true);

            var token = fixture.TokenGenerator.GenerateToken();

            fixture.WellKnownSetup();
            fixture.SetupCertificates();
            fixture.AuthSetup(token, refreshToken);
            var sut = fixture.Instance;

            // act
            var result = await sut.CheckSigninAsync(tokenName);

            // assert
            result.Should().BeNull();
            loggerMock.Verify(t => t.Error("Error occured during user authentication. {Error}", It.IsAny <string>()),
                              Times.Once);

            fixture.HttpMock.HttpMock.Dispose();
        }
Beispiel #2
0
        public async Task SetupWithCheckThatPostCannotOccurPriorToInitialization()
        {
            // arrange
            _logMock = LoggerFixture.SetupLogCatcher();

            // act
            AppInsightClient.TrackEvent("BeforeStart");

            // assert
            _logMock.Verify(t => t.Warning("Cannot track telemetry - Client has not been initialized"), Times.Once);

            await AppInsightClient.InitializeAsync(TestKey, TestUserKey);
        }
Beispiel #3
0
        public async Task FailureToGetATokenWithTimerRefreshDoesNotBroadcastARefreshEvent()
        {
            // arrange
            var          loggerDummy    = LoggerFixture.SetupLogCatcher();
            var          refreshTimeout = TimeSpan.FromSeconds(10);
            const string tokenName      = "Test Token";
            var          refreshToken   = Guid.NewGuid().ToString();
            var          fixture        = new TokenManagerFixture();
            await fixture.SetupServerDataAsync(tokenName, true);

            var token = fixture.TokenGenerator.GenerateToken(DateTime.UtcNow.AddMinutes(-15),
                                                             DateTime.UtcNow.AddSeconds(15), DateTime.UtcNow.AddMinutes(-17));
            var tokenDataDummy = new TokenData(token);
            var wasRefreshed   = false;

            fixture.TokenStorageMock
            .Setup(t => t.RetrieveAccessTokenAsync(tokenName))
            .ReturnsAsync(tokenDataDummy);
            fixture.TokenStorageMock
            .Setup(t => t.RetrieveRefreshTokenAsync(tokenName))
            .ReturnsAsync(refreshToken);

            fixture.WellKnownSetup();
            fixture.SetupCertificates();
            fixture.AuthRefreshSetup(null, null);
            var sut = fixture.Instance;

            sut.SetupRefreshTimeSpan(refreshTimeout);
            sut.TokenRefreshed += (sender, pair) => { wasRefreshed = true; };

            // act
            await sut.CheckSigninAsync(tokenName);

            await Task.Delay(TimeSpan.FromSeconds(10));

            // assert
            wasRefreshed.Should().BeFalse();
            loggerDummy.Verify(
                t => t.Warning(
                    "Attempting to refresh access token failed. No further auto-refreshes will occur for {TokenName}",
                    tokenName), Times.Once);

            fixture.HttpMock.Dispose();
        }
        public async Task FailureDuringRefreshTokenRetrievalWillResultInFullTokenRetrieval()
        {
            // arrange
            var          loggerMock   = LoggerFixture.SetupLogCatcher();
            const string tokenName    = "Test Token";
            var          refreshToken = Guid.NewGuid().ToString();
            var          fixture      = new TokenManagerFixture();
            await fixture.SetupServerDataAsync(tokenName);

            var token = fixture.TokenGenerator.GenerateToken(DateTime.UtcNow.AddMinutes(-15),
                                                             DateTime.UtcNow.AddMinutes(-10), DateTime.UtcNow.AddMinutes(-17));
            var tokenDataDummy = new TokenData(token);
            var newAccessToken = fixture.TokenGenerator.GenerateToken();

            fixture.TokenStorageMock
            .Setup(t => t.RetrieveAccessTokenAsync(tokenName))
            .ReturnsAsync(tokenDataDummy);
            fixture.TokenStorageMock
            .Setup(t => t.RetrieveRefreshTokenAsync(tokenName))
            .ReturnsAsync(refreshToken);

            fixture.WellKnownSetup();
            fixture.SetupCertificates();
            fixture.AuthRefreshSetup(newAccessToken, refreshToken, true);
            fixture.AuthSetup(newAccessToken, refreshToken);
            fixture.UserInfoSetup();
            var sut = fixture.Instance;

            // act
            await sut.CheckSigninAsync(tokenName);

            // assert
            loggerMock.Verify(t =>
                              t.Error("Error occured while trying to refresh Access Token. {Error}", It.IsAny <string>()));
            //result.Should().NotBeNull();
            loggerMock.Verify(t => t.Error("Error occured during user authentication. {Error}", It.IsAny <string>()),
                              Times.Once);

            fixture.HttpMock.HttpMock.Dispose();
        }