예제 #1
0
        public Task Create(SingleUseToken token, DateTimeOffset expiration)
        {
            this.Create_InputToken      = token;
            this.Create_InputExpiration = expiration;

            return(Task.CompletedTask);
        }
        protected override async Task <SingleUseTokenData?> Retrieve(SingleUseToken token)
        {
            Guard.Null(nameof(token), token);

            var model = await this.Store.Retrieve(token).ConfigureAwait(false);

            return(model?.ToData());
        }
예제 #3
0
                public async Task ValidToken_ReturnsTrue()
                {
                    var token      = new SingleUseToken("token");
                    var clock      = Clock();
                    var expiration = clock.UtcNow.ToOffset().AddHours(1);
                    var service    = new FakeSingleUseTokenServiceBase(clock);

                    await service.Create(token, new UtcDateTime(expiration));

                    Assert.True(await service.Validate(token));
                }
예제 #4
0
                public async Task TokenNotExists_ReturnsFalse()
                {
                    var token   = new SingleUseToken("token");
                    var clock   = Clock();
                    var service = new FakeSingleUseTokenServiceBase(clock)
                    {
                        Retrieve_ShouldReturnData = false
                    };

                    Assert.False(await service.Validate(token));
                }
예제 #5
0
                public async Task TokenExpired_ReturnsFalse()
                {
                    var token      = new SingleUseToken("token");
                    var clock      = Clock();
                    var expiration = clock.UtcNow.ToOffset().AddHours(-1);
                    var service    = new FakeSingleUseTokenServiceBase(clock)
                    {
                        Retrieve_Output_Expiration = expiration
                    };

                    Assert.False(await service.Validate(token));
                }
예제 #6
0
                public async Task WhenCalled_CallsCreateOnService()
                {
                    var token      = new SingleUseToken("token");
                    var clock      = Clock();
                    var expiration = clock.UtcNow.ToOffset().AddHours(1);
                    var service    = new FakeSingleUseTokenServiceBase(clock);

                    await service.Create(token, new UtcDateTime(expiration));

                    Assert.Equal(token.Value, service.Create_InputData_Value);
                    Assert.Equal(expiration, service.Create_InputData_Expiration);
                }
예제 #7
0
                public async Task ExpirationAlreadyPassed_Throws()
                {
                    var token      = new SingleUseToken("token");
                    var clock      = Clock();
                    var expiration = clock.UtcNow.ToOffset().AddHours(-1);
                    var service    = new FakeSingleUseTokenServiceBase(clock);

                    await Assert.ThrowsAsync <InvalidOperationException>(async() =>
                    {
                        await service.Create(token, new UtcDateTime(expiration));
                    });
                }
예제 #8
0
        public virtual Task Create(SingleUseToken token, UtcDateTime expiration)
        {
            Guard.Null(nameof(token), token);

            var record = new SingleUseTokenData(token, expiration);

            if (record.IsExpired(this._clock))
            {
                throw new InvalidOperationException("Unable to create this token because it will have already expired.");
            }

            return(this.Create(record));
        }
예제 #9
0
                public async Task TokenExpired_DeletesToken()
                {
                    var token      = new SingleUseToken("token");
                    var clock      = Clock();
                    var expiration = clock.UtcNow.ToOffset().AddHours(-1);
                    var service    = new FakeSingleUseTokenServiceBase(clock)
                    {
                        Retrieve_Output_Expiration = expiration
                    };

                    await service.Validate(token);

                    Assert.Equal(token.Value, service.Delete_InputData_Value);
                    Assert.Equal(expiration, service.Delete_InputData_Expiration);
                }
        protected override Task <SingleUseTokenData?> Retrieve(SingleUseToken token)
        {
            this.Retrieve_InputToken = token;

            if (this.Retrieve_ShouldReturnData)
            {
                this.Retrieve_Output_Value = token.Value;

                return(Task.FromResult <SingleUseTokenData?>(
                           new SingleUseTokenData(token,
                                                  new UtcDateTime(this.Retrieve_Output_Expiration))));
            }

            return(Task.FromResult <SingleUseTokenData?>(null));
        }
예제 #11
0
        public virtual async Task <bool> Validate(SingleUseToken token)
        {
            Guard.Null(nameof(token), token);

            var record = await this.Retrieve(token).ConfigureAwait(false);

            if (record != null)
            {
                await this.Delete(record).ConfigureAwait(false);

                if (!record.IsExpired(this._clock))
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #12
0
 public SingleUseTokenData(SingleUseToken token, UtcDateTime expiration)
     : this(Guard.Null(nameof(token), token).Value, expiration)
 {
 }
예제 #13
0
        public Task <bool> Validate(SingleUseToken token)
        {
            this.Validate_InputToken = token;

            return(Task.FromResult(this.Validate_Output));
        }
 protected static TableEntityKeys CreateKeys(SingleUseToken token) =>
 new TableEntityKeys(Guard.Null(nameof(token), token).Value, "Token");
예제 #15
0
 new public static TableEntityKeys CreateKeys(SingleUseToken token) =>
 TableSingleUseTokenService.CreateKeys(token);
예제 #16
0
 new public Task <SingleUseTokenData?> Retrieve(SingleUseToken token) =>
 base.Retrieve(token);
예제 #17
0
 protected abstract Task <SingleUseTokenData?> Retrieve(SingleUseToken token);