Beispiel #1
0
        public async Task GetTokenAsyncTokensChangeOnEachIssue()
        {
            var signature = new SharedAccessSignature("SharedAccessSignature sr=amqps%3A%2F%2Fmy.eh.com%2Fsomepath%2F&sig=%2BLsuqDlN8Us5lp%2FGdyEUMnU1XA4HdXx%2BJUdtkRNr7qI%3D&se=1562258488&skn=keykeykey", "ABC123");
            var provider  = new TrackOneSharedAccessTokenProvider(signature);
            var first     = await provider.GetTokenAsync(signature.Resource, TimeSpan.FromHours(1));

            var second = await provider.GetTokenAsync(signature.Resource, TimeSpan.FromMinutes(10));

            Assert.That(first.TokenValue, Is.Not.EqualTo(second.TokenValue));
        }
Beispiel #2
0
        public void GetTokenAsyncValidatesTheDuration()
        {
            var signature = new SharedAccessSignature("SharedAccessSignature sr=amqps%3A%2F%2Fmy.eh.com%2Fsomepath%2F&sig=%2BLsuqDlN8Us5lp%2FGdyEUMnU1XA4HdXx%2BJUdtkRNr7qI%3D&se=1562258488&skn=keykeykey", "ABC123");
            var provider  = new TrackOneSharedAccessTokenProvider(signature);

            Assert.That(async() => await provider.GetTokenAsync(signature.Resource, TimeSpan.FromMilliseconds(-1)), Throws.InstanceOf <ArgumentException>());
        }
Beispiel #3
0
        public void GetTokenAsyncDisallowsInvalideResources(string invalidResource)
        {
            var resource  = WebUtility.UrlEncode("amqps://my.eventhubs.com/someHub");
            var signature = new SharedAccessSignature($"SharedAccessSignature sr={ resource }&sig=%2BLsuqDlN8Us5lp%2FGdyEUMnU1XA4HdXx%2BJUdtkRNr7qI%3D&se=1562258488&skn=keykeykey", "ABC123");
            var provider  = new TrackOneSharedAccessTokenProvider(signature);

            Assert.That(async() => await provider.GetTokenAsync(invalidResource, TimeSpan.FromHours(4)), Throws.InstanceOf <ArgumentException>());
        }
Beispiel #4
0
        public async Task GetTokenAsyncProducesTokenForTheResource()
        {
            var signature = new SharedAccessSignature("SharedAccessSignature sr=amqps%3A%2F%2Fmy.eh.com%2Fsomepath%2F&sig=%2BLsuqDlN8Us5lp%2FGdyEUMnU1XA4HdXx%2BJUdtkRNr7qI%3D&se=1562258488&skn=keykeykey", "ABC123");
            var provider  = new TrackOneSharedAccessTokenProvider(signature);
            var token     = await provider.GetTokenAsync(signature.Resource, TimeSpan.FromHours(1));

            Assert.That(token, Is.Not.Null, "A token should have been produced.");
            Assert.That(token.Audience, Is.EqualTo(signature.Resource), "The audience of the token should match the signature.");
        }
Beispiel #5
0
        public async Task GetTokenAsyncProducesASharedAccessSignatureToken()
        {
            var signature = new SharedAccessSignature("SharedAccessSignature sr=amqps%3A%2F%2Fmy.eh.com%2Fsomepath%2F&sig=%2BLsuqDlN8Us5lp%2FGdyEUMnU1XA4HdXx%2BJUdtkRNr7qI%3D&se=1562258488&skn=keykeykey", "ABC123");
            var provider  = new TrackOneSharedAccessTokenProvider(signature);

            TrackOne.SecurityToken token = await provider.GetTokenAsync(signature.Resource, TimeSpan.FromHours(1));

            Assert.That(token, Is.Not.Null, "A token should have been produced.");
            Assert.That(token, Is.InstanceOf <TrackOneSharedAccessSignatureToken>(), "The token should be a SAS token.");
        }
Beispiel #6
0
        public async Task GetTokenAsyncProducesTokenWithCorrectExpiration()
        {
            var signature  = new SharedAccessSignature("SharedAccessSignature sr=amqps%3A%2F%2Fmy.eh.com%2Fsomepath%2F&sig=%2BLsuqDlN8Us5lp%2FGdyEUMnU1XA4HdXx%2BJUdtkRNr7qI%3D&se=1562258488&skn=keykeykey", "ABC123");
            var provider   = new TrackOneSharedAccessTokenProvider(signature);
            var duration   = TimeSpan.FromHours(1.5);
            var expiration = DateTime.UtcNow.Add(duration);
            var token      = await provider.GetTokenAsync(signature.Resource, duration);

            Assert.That(token, Is.Not.Null, "A token should have been produced.");
            Assert.That(token.ExpiresAtUtc, Is.EqualTo(expiration).Within(TimeSpan.FromSeconds(5)), "The expiration of the token should match the requested duration.");
        }