public void ShouldGenerateNewNonceAfterSomeTime()
 {
     var nonceGenerator = new NonceGenerator(new PrivateHashEncoder(TestResources.PrivateKey, new MD5Encoder()),
                                          new Base64Converter());
      string firstNonce = nonceGenerator.Generate(TestResources.IpAddress);
      Thread.Sleep(10);
      string secondNonce = nonceGenerator.Generate(TestResources.IpAddress);
      Assert.That(firstNonce, Is.Not.EqualTo(secondNonce));
 }
        public void ShouldIndicateThatNonceIsNotStale()
        {
            var md5Encoder = new MD5Encoder();
             var base64Converter = new Base64Converter();
             var privateHashEncoder = new PrivateHashEncoder(TestResources.PrivateKey, md5Encoder);

             var nonceTimeStampParser = new NonceTimeStampParser();
             var nonceValidator = new NonceValidator(privateHashEncoder, base64Converter, nonceTimeStampParser, 600);
             var nonceGenerator = new NonceGenerator(privateHashEncoder, base64Converter);

             bool result = nonceValidator.IsStale(nonceGenerator.Generate(TestResources.IpAddress));
             Assert.That(result, Is.False);
        }
        public void ShouldGenerateNewNonce()
        {
            var repository = new MockRepository();
             var base64Converter = repository.Stub<Base64Converter>();
             var privateHashEncoder = repository.DynamicMock<PrivateHashEncoder>(null, null);
             using (repository.Record())
             {
            privateHashEncoder.Expect(hashEncoder => hashEncoder.Encode(string.Empty, string.Empty)).IgnoreArguments().Return("");
             }

             using (repository.Playback())
             {
            var nonceGenerator = new NonceGenerator(privateHashEncoder, base64Converter);
            nonceGenerator.Generate(string.Empty);
             }
             repository.VerifyAll();
        }
 public static RequestInterceptor Create(string realm, string privateKey, MembershipProvider membershipProvider)
 {
     var base64Converter = new Base64Converter();
      var privateHashEncoder = new PrivateHashEncoder(privateKey, new MD5Encoder());
      var generator = new NonceGenerator(privateHashEncoder, base64Converter);
      var digestHeaderGenerator = new DigestHeaderFactory(generator, realm);
      var digestValidator = new DigestValidator(new DigestEncoders(new MD5Encoder()));
      var digestHeaderExtractor = new DigestHeaderExtractor(new AuthorizationStringExtractor(), new DigestHeaderParser(new HeaderKeyValueSplitter('=')), new MethodExtractor());
      var nonceValidator = new NonceValidator(privateHashEncoder, base64Converter, new NonceTimeStampParser(), 600);
      var digestAuthenticationManager = new DigestAuthenticationManager(
     new ResponseMessageFactory(),
     new IPAddressExtractor(),
     membershipProvider,
     digestHeaderExtractor,
     new ServiceSecurityContextFactory(new AuthorizationPolicyFactory()),
     nonceValidator,
     digestValidator,
     digestHeaderGenerator);
      return new DigestAuthenticationInterceptor(digestAuthenticationManager);
 }