public void ShouldParseAuthenticationStringWhenAuthorizationStringIsAvailable() { MockRepository repository = new MockRepository(); DigestHeaderParser headerParser = MockCreator<DigestHeaderParser>.Stub(repository); MethodExtractor methodExtractor = MockCreator<MethodExtractor>.Stub(repository); Message testMessage = TestResources.CreateMessage(); AuthorizationStringExtractor extractor; using (repository.Record()) { headerParser.Expect(parser => parser.Parse(string.Empty)).IgnoreArguments().Return(TestResources.CreateHeader()); extractor = MockCreator<AuthorizationStringExtractor>.Create(repository); string authenticationString; extractor.Expect(extr => extr.TryExtractAuthorizationHeader(testMessage, out authenticationString)).OutRef(TestResources.AuthenticationString).Return(true); } var digestHeaderExtractor = new DigestHeaderExtractor(extractor, headerParser, methodExtractor); using (repository.Playback()) { DigestHeader digestHeader; bool result = digestHeaderExtractor.TryExtract(testMessage, out digestHeader); Assert.That(result, Is.True); } }
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); }