Exemple #1
0
        public void GetTokenReturnsTheSignatureValue()
        {
            var value      = "TOkEn!";
            var signature  = new SharedAccessSignature("hub-name", "keyName", "key", value, DateTimeOffset.UtcNow.AddHours(4));
            var credential = new SharedAccessSignatureCredential(signature);

            Assert.That(credential.GetToken(new TokenRequestContext(), default).Token, Is.SameAs(signature.Value), "The credential should return the signature as the token.");
        }
Exemple #2
0
        public void GetTokenIgnoresScopeAndCancellationToken()
        {
            var value      = "TOkEn!";
            var signature  = new SharedAccessSignature("hub-name", "keyName", "key", value, DateTimeOffset.UtcNow.AddHours(4));
            var credential = new SharedAccessSignatureCredential(signature);

            Assert.That(credential.GetToken(new TokenRequestContext(new[] { "test", "this" }), CancellationToken.None).Token, Is.SameAs(signature.Value), "The credential should return the signature as the token.");
        }
Exemple #3
0
        public void GetTokenIgnoresScopeAndCancellationToken()
        {
            var value      = "TOkEn!";
            var signature  = new SettablePropertiesMock(value: value);
            var credential = new SharedAccessSignatureCredential(signature);

            Assert.That(credential.GetToken(new[] { "test", "this" }, CancellationToken.None), Is.SameAs(signature.Value), "The credential should return the signature as the token.");
        }
Exemple #4
0
        public void GetTokenReturnsTheSignatureValue()
        {
            var value      = "TOkEn!";
            var signature  = new SettablePropertiesMock(value: value);
            var credential = new SharedAccessSignatureCredential(signature);

            Assert.That(credential.GetToken(null, default), Is.SameAs(signature.Value), "The credential should return the signature as the token.");
        }
        public void GetTokenReturnsTheSignatureValue()
        {
            var value      = "TOkEn!";
            var signature  = new SharedAccessSignature(String.Empty, "keyName", "key", value, DateTime.UtcNow.AddHours(4));
            var credential = new SharedAccessSignatureCredential(signature);

            Assert.That(credential.GetToken(null, default).Token, Is.SameAs(signature.Value), "The credential should return the signature as the token.");
        }
Exemple #6
0
        public void GetTokenDoesNotExtendATokenCloseToExpiringWhenCreatedWithoutTheKey()
        {
            var tokenExpiration = DateTimeOffset.UtcNow.Add(TimeSpan.FromSeconds(GetSignatureRefreshBuffer().TotalSeconds / 2));
            var value           = $"SharedAccessSignature sr=https%3A%2F%2Ffake-test.servicebus.windows.net%2F&sig=nNBNavJfBiHuXUzWOLhSvI3bVgqbQUzA7Po8%2F4wQQng%3D&se={ ToUnixTime(tokenExpiration) }&skn=fakeKey";
            var sourceSignature = new SharedAccessSignature("fake-test", "fakeKey", "ABC123", value, tokenExpiration).Value;
            var signature       = new SharedAccessSignature(sourceSignature);
            var credential      = new SharedAccessSignatureCredential(signature);

            Assert.That(credential.GetToken(new TokenRequestContext(), default).ExpiresOn, Is.EqualTo(tokenExpiration).Within(TimeSpan.FromMinutes(1)));
        }
Exemple #7
0
        public void GetTokenDoesNotExtendAnExpiredTokenWhenCreatedWithoutTheKey()
        {
            var expectedExpiration = DateTimeOffset.UtcNow.Subtract(TimeSpan.FromHours(2));
            var value           = $"SharedAccessSignature sr=https%3A%2F%2Ffake-test.servicebus.windows.net%2F&sig=nNBNavJfBiHuXUzWOLhSvI3bVgqbQUzA7Po8%2F4wQQng%3D&se={ ToUnixTime(expectedExpiration) }&skn=fakeKey";
            var sourceSignature = new SharedAccessSignature("fake-test", "fakeKey", "ABC123", value, expectedExpiration).Value;
            var signature       = new SharedAccessSignature(sourceSignature);
            var credential      = new SharedAccessSignatureCredential(signature);

            Assert.That(credential.GetToken(new TokenRequestContext(), default).ExpiresOn, Is.EqualTo(expectedExpiration).Within(TimeSpan.FromMinutes(1)));
        }
Exemple #8
0
        public void GetTokenExtendsAnExpiredTokenWhenCreatedWithTheSharedKey()
        {
            var value      = "TOkEn!";
            var signature  = new SharedAccessSignature("hub-name", "keyName", "key", value, DateTimeOffset.UtcNow.Subtract(TimeSpan.FromHours(2)));
            var credential = new SharedAccessSignatureCredential(signature);

            var expectedExpiration = DateTimeOffset.Now.Add(GetSignatureExtensionDuration());

            Assert.That(credential.GetToken(new TokenRequestContext(), default).ExpiresOn, Is.EqualTo(expectedExpiration).Within(TimeSpan.FromMinutes(1)));
        }
Exemple #9
0
        public void GetTokenExtendsATokenCloseToExpiringWhenCreatedWithTheSharedKey()
        {
            var value           = "TOkEn!";
            var tokenExpiration = DateTimeOffset.UtcNow.Add(TimeSpan.FromSeconds(GetSignatureRefreshBuffer().TotalSeconds / 2));
            var signature       = new SharedAccessSignature("hub-name", "keyName", "key", value, tokenExpiration);
            var credential      = new SharedAccessSignatureCredential(signature);

            var expectedExpiration = DateTimeOffset.Now.Add(GetSignatureExtensionDuration());

            Assert.That(credential.GetToken(new TokenRequestContext(), default).ExpiresOn, Is.EqualTo(expectedExpiration).Within(TimeSpan.FromMinutes(1)));
        }