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)); }
public NonceValidator( PrivateHashEncoder privateHashEncoder, Base64Converter base64Converter, NonceTimeStampParser nonceTimeStampParser, int staleTimeOutInSeconds) { this.privateHashEncoder = privateHashEncoder; this.base64Converter = base64Converter; this.nonceTimeStampParser = nonceTimeStampParser; this.staleTimeOutInSeconds = staleTimeOutInSeconds; }
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); }
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); }
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 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); }
public void ShouldReturnNullWhenNullIsGivenToEncode() { var base64Converter = new Base64Converter(); string result = base64Converter.Encode(null); Assert.That(result, Is.EqualTo(null)); }
public void ShouldBase64EncodeARandomString() { var base64Converter = new Base64Converter(); string result = base64Converter.Encode("Hello Base64"); Assert.That(result, Is.EqualTo("SGVsbG8gQmFzZTY0")); }
public NonceGenerator(PrivateHashEncoder privateHashEncoder, Base64Converter base64Converter) { this.privateHashEncoder = privateHashEncoder; this.base64Converter = base64Converter; }