コード例 #1
0
        public void ShouldDecodeBase64String()
        {
            const string Base64EncodedData = "SGVsbG8gQmFzZTY0";
             const string DecodedData = "Hello Base64";

             var base64Converter = new Base64Converter();
             string result = base64Converter.Decode(Base64EncodedData);

             Assert.That(DecodedData, Is.EqualTo(result));
        }
コード例 #2
0
 public NonceValidator(
  PrivateHashEncoder privateHashEncoder, 
  Base64Converter base64Converter,
  NonceTimeStampParser nonceTimeStampParser, 
  int staleTimeOutInSeconds)
 {
     this.privateHashEncoder = privateHashEncoder;
      this.base64Converter = base64Converter;
      this.nonceTimeStampParser = nonceTimeStampParser;
      this.staleTimeOutInSeconds = staleTimeOutInSeconds;
 }
コード例 #3
0
        public void ShouldPositivelyValidateNonceWhenNonceIsGeneratedUsingPrivateKey()
        {
            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);
             bool result = nonceValidator.Validate(TestResources.GeneratedValidNonce, TestResources.IpAddress);
             Assert.That(result, Is.True);
        }
コード例 #4
0
        public void ShouldIndicateThatNonceIsStaleWithOldTimeStamp()
        {
            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);
             bool result = nonceValidator.IsStale(TestResources.GeneratedValidNonce);
             Assert.That(result, Is.True);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
 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);
 }
コード例 #7
0
 public void ShouldReturnNullWhenNullIsGivenToEncode()
 {
     var base64Converter = new Base64Converter();
      string result = base64Converter.Encode(null);
      Assert.That(result, Is.EqualTo(null));
 }
コード例 #8
0
 public void ShouldBase64EncodeARandomString()
 {
     var base64Converter = new Base64Converter();
      string result = base64Converter.Encode("Hello Base64");
      Assert.That(result, Is.EqualTo("SGVsbG8gQmFzZTY0"));
 }
コード例 #9
0
 public NonceGenerator(PrivateHashEncoder privateHashEncoder, Base64Converter base64Converter)
 {
     this.privateHashEncoder = privateHashEncoder;
      this.base64Converter = base64Converter;
 }