Exemple #1
0
        public void InspectContextForUniqueNoncePasses()
        {
            var nonceStore = MockRepository.GenerateStub <INonceStore>();

            var context = new OAuthContext {
                Nonce = "2"
            };

            nonceStore.Stub(stub => stub.RecordNonceAndCheckIsUnique(context, "2")).Return(true);

            var inspector = new NonceStoreInspector(nonceStore);

            Assert.DoesNotThrow(() => inspector.InspectContext(ProviderPhase.GrantRequestToken, context));
        }
Exemple #2
0
        public void InspectContextForRepeatedNonceThrows()
        {
            var nonceStore = MockRepository.GenerateStub <INonceStore>();

            var context = new OAuthContext {
                Nonce = "1"
            };

            nonceStore.Stub(stub => stub.RecordNonceAndCheckIsUnique(context, "1")).Return(false);

            var inspector = new NonceStoreInspector(nonceStore);

            var ex = Assert.Throws <OAuthException>(() => inspector.InspectContext(ProviderPhase.GrantRequestToken, context));

            Assert.Equal("The nonce value \"1\" has already been used", ex.Message);
        }
        public void InspectContextForUniqueNoncePasses()
        {
            var repository = new MockRepository();

            var nonceStore = repository.StrictMock <INonceStore>();
            var context    = new OAuthContext {
                Nonce = "2"
            };

            using (repository.Record())
            {
                Expect.Call(nonceStore.RecordNonceAndCheckIsUnique(context, "2")).Return(true);
            }
            using (repository.Playback())
            {
                var inspector = new NonceStoreInspector(nonceStore);
                inspector.InspectContext(ProviderPhase.GrantRequestToken, context);
            }
        }