public void Setup()
 {
     dropbox                     = new DropboxTemplate("CONSUMER_KEY", "CONSUMER_SECRET", "ACCESS_TOKEN", "ACCESS_TOKEN_SECRET", AccessLevel.Full);
     mockServer                  = MockRestServiceServer.CreateServer(dropbox.RestTemplate);
     responseHeaders             = new HttpHeaders();
     responseHeaders.ContentType = MediaType.APPLICATION_JSON;
 }
 public void Setup()
 {
     twitter                     = new TwitterTemplate("API_KEY", "API_SECRET", "ACCESS_TOKEN", "ACCESS_TOKEN_SECRET");
     mockServer                  = MockRestServiceServer.CreateServer(twitter.RestTemplate);
     responseHeaders             = new HttpHeaders();
     responseHeaders.ContentType = MediaType.APPLICATION_JSON;
 }
Exemple #3
0
        private AccessGrant AuthenticateClient(bool expectParamBasedClientAuthentication, string responseFile)
        {
            OAuth2Template testedOAuth2Template = expectParamBasedClientAuthentication ? oAuth2TemplateParamBasedClientAuthentication : oAuth2Template;

            HttpHeaders responseHeaders = new HttpHeaders();

            responseHeaders.ContentType = MediaType.APPLICATION_JSON;
            MockRestServiceServer mockServer     = MockRestServiceServer.CreateServer(testedOAuth2Template.RestTemplate);
            IRequestActions       requestActions = mockServer.ExpectNewRequest()
                                                   .AndExpectUri(ACCESS_TOKEN_URL)
                                                   .AndExpectMethod(HttpMethod.POST)
                                                   .AndExpectBody((expectParamBasedClientAuthentication ? "client_id=client_id&client_secret=client_secret&" : "") + "grant_type=client_credentials&scope=read%2Cwrite");

            if (!expectParamBasedClientAuthentication)
            {
                requestActions.AndExpectHeader("Authorization", "Basic Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ=");
            }
            requestActions.AndRespondWith(new AssemblyResource(responseFile, typeof(OAuth2TemplateTests)), responseHeaders);

            OAuth2Parameters parameters = new OAuth2Parameters();

            parameters.Scope = "read,write";
#if NET_4_0 || SILVERLIGHT_5
            AccessGrant accessGrant = testedOAuth2Template.AuthenticateClientAsync("read,write").Result;
#else
            AccessGrant accessGrant = testedOAuth2Template.AuthenticateClient("read,write");
#endif
            return(accessGrant);
        }
Exemple #4
0
        // private helpers

        private AccessGrant ExchangeForAccess(bool expectParamBasedClientAuthentication, string responseFile)
        {
            OAuth2Template testedOAuth2Template = expectParamBasedClientAuthentication ? oAuth2TemplateParamBasedClientAuthentication : oAuth2Template;

            HttpHeaders responseHeaders = new HttpHeaders();

            responseHeaders.ContentType = MediaType.APPLICATION_JSON;
            MockRestServiceServer mockServer     = MockRestServiceServer.CreateServer(testedOAuth2Template.RestTemplate);
            IRequestActions       requestActions = mockServer.ExpectNewRequest()
                                                   .AndExpectUri(ACCESS_TOKEN_URL)
                                                   .AndExpectMethod(HttpMethod.POST)
                                                   .AndExpectBody((expectParamBasedClientAuthentication ? "client_id=client_id&client_secret=client_secret&" : "") + "code=code&redirect_uri=http%3A%2F%2Fwww.someclient.com%2Fcallback&grant_type=authorization_code");

            if (!expectParamBasedClientAuthentication)
            {
                requestActions.AndExpectHeader("Authorization", "Basic Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ=");
            }
            requestActions.AndRespondWith(new AssemblyResource(responseFile, typeof(OAuth2TemplateTests)), responseHeaders);

#if NET_4_0 || SILVERLIGHT_5
            AccessGrant accessGrant = testedOAuth2Template.ExchangeForAccessAsync("code", "http://www.someclient.com/callback", null).Result;
#else
            AccessGrant accessGrant = testedOAuth2Template.ExchangeForAccess("code", "http://www.someclient.com/callback", null);
#endif
            return(accessGrant);
        }
 public void Setup()
 {
     linkedIn                    = new LinkedInTemplate("API_KEY", "API_SECRET", "ACCESS_TOKEN", "ACCESS_TOKEN_SECRET");
     mockServer                  = MockRestServiceServer.CreateServer(linkedIn.RestTemplate);
     responseHeaders             = new HttpHeaders();
     responseHeaders.ContentType = new MediaType("application", "json", Encoding.Default);
 }
        public void FetchNewRequestToken_OAuth10a()
        {
            MockRestServiceServer mockServer      = MockRestServiceServer.CreateServer(oauth10a.RestTemplate);
            HttpHeaders           responseHeaders = new HttpHeaders();

            responseHeaders.ContentType = MediaType.APPLICATION_FORM_URLENCODED;
            mockServer.ExpectNewRequest()
            .AndExpectUri(REQUEST_TOKEN_URL)
            .AndExpectMethod(HttpMethod.POST)
            .AndExpectHeaderContains("Authorization", "oauth_callback=\"http%3A%2F%2Fwww.someclient.com%2Foauth%2Fcallback\"")
            .AndExpectHeaderContains("Authorization", "oauth_version=\"1.0\"")
            .AndExpectHeaderContains("Authorization", "oauth_signature_method=\"HMAC-SHA1\"")
            .AndExpectHeaderContains("Authorization", "oauth_consumer_key=\"consumer_key\"")
            .AndExpectHeaderContains("Authorization", "oauth_nonce=\"")
            .AndExpectHeaderContains("Authorization", "oauth_signature=\"")
            .AndExpectHeaderContains("Authorization", "oauth_timestamp=\"")
            .AndRespondWith(EmbeddedResource("RequestToken.formencoded"), responseHeaders);

#if NET_4_0 || SILVERLIGHT_5
            OAuthToken requestToken = oauth10a.FetchRequestTokenAsync("http://www.someclient.com/oauth/callback", null).Result;
#else
            OAuthToken requestToken = oauth10a.FetchRequestToken("http://www.someclient.com/oauth/callback", null);
#endif
            Assert.AreEqual("1234567890", requestToken.Value);
            Assert.AreEqual("abcdefghijklmnop", requestToken.Secret);
        }
        public void ExchangeForAccessToken_OAuth10()
        {
            MockRestServiceServer mockServer      = MockRestServiceServer.CreateServer(oauth10.RestTemplate);
            HttpHeaders           responseHeaders = new HttpHeaders();

            responseHeaders.ContentType = MediaType.APPLICATION_FORM_URLENCODED;
            mockServer.ExpectNewRequest()
            .AndExpectUri(ACCESS_TOKEN_URL)
            .AndExpectMethod(HttpMethod.POST)
            .AndExpectHeaderContains("Authorization", "oauth_version=\"1.0\"")
            .AndExpectHeaderContains("Authorization", "oauth_signature_method=\"HMAC-SHA1\"")
            .AndExpectHeaderContains("Authorization", "oauth_consumer_key=\"consumer_key\"")
            .AndExpectHeaderContains("Authorization", "oauth_token=\"1234567890\"")
            .AndExpectHeaderContains("Authorization", "oauth_nonce=\"")
            .AndExpectHeaderContains("Authorization", "oauth_signature=\"")
            .AndExpectHeaderContains("Authorization", "oauth_timestamp=\"")
            .AndRespondWith(EmbeddedResource("AccessToken.formencoded"), responseHeaders);

            OAuthToken requestToken = new OAuthToken("1234567890", "abcdefghijklmnop");

#if NET_4_0 || SILVERLIGHT_5
            OAuthToken accessToken = oauth10.ExchangeForAccessTokenAsync(new AuthorizedRequestToken(requestToken, "verifier"), null).Result;
#else
            OAuthToken accessToken = oauth10.ExchangeForAccessToken(new AuthorizedRequestToken(requestToken, "verifier"), null);
#endif
            Assert.AreEqual("9876543210", accessToken.Value);
            Assert.AreEqual("ponmlkjihgfedcba", accessToken.Secret);
        }
        public void Setup()
        {
            restBucksClient = new RestBucksClient();
            mockServer      = MockRestServiceServer.CreateServer(this.restBucksClient.RestTemplate);

            responseHeaders             = new HttpHeaders();
            responseHeaders.ContentType = new MediaType("application", "vnd.restbucks+xml");
        }
Exemple #9
0
        // private helpers

        private static void AssertThatRequestInterceptorWritesAuthorizationHeader(AbstractOAuth2ApiBinding apiBinding, string expectedAuthorizationHeaderValue)
        {
            MockRestServiceServer mockServer = MockRestServiceServer.CreateServer(apiBinding.RestTemplate);

            mockServer.ExpectNewRequest()
            .AndExpectUri("https://api.someprovider.com/status/update")
            .AndExpectMethod(HttpMethod.POST)
            .AndExpectHeader("Content-Type", MediaType.APPLICATION_FORM_URLENCODED.ToString())
            .AndExpectHeader("Authorization", expectedAuthorizationHeaderValue)
            .AndExpectBody("status=Hello+there%21");
        }
 public SpecificationsBase()
 {
     twitter          = new TwitterTemplate("API_KEY", "API_SECRET", "ACCESS_TOKEN", "ACCESS_TOKEN_SECRET");
     mockServer       = MockRestServiceServer.CreateServer(twitter.RestTemplate);
     dbContextFactory = () => new TestDbContext();
     containerFactory = dbContext => new Container
     {
         RepositoryFactory =
             () => new SimpleRepository(dbContext ?? dbContextFactory()),
     };
     sessionFactory = () => new TestSessionAdapter();
 }
Exemple #11
0
 void PrepareMocks()
 {
     _restTemplate = new RestTemplate(BaseUrl);
     _restTemplate.MessageConverters.Add(new NJsonHttpMessageConverter());
     _mockRestServer  = MockRestServiceServer.CreateServer(_restTemplate);
     _responseHeaders = new HttpHeaders {
         ContentType = new MediaType("application", "json")
     };
     ClientSettings.Instance.ServerUrl = BaseUrl;
     _restRequestCreator = new RestRequestCreator();
     _restRequestCreator.SetRestTemplate(_restTemplate);
     RestRequestFactory.RestRequestCreator = _restRequestCreator;
 }
Exemple #12
0
        public void RequestInterceptor()
        {
            AbstractOAuth1ApiBindingTests apiBinding = new AbstractOAuth1ApiBindingTests("consumer_key", "consumer_secret", "access_token", "token_secret");

            MockRestServiceServer mockServer = MockRestServiceServer.CreateServer(apiBinding.RestTemplate);

            mockServer.ExpectNewRequest()
            .AndExpectUri("https://api.someprovider.com/status/update")
            .AndExpectMethod(HttpMethod.POST)
            .AndExpectHeader("Content-Type", MediaType.APPLICATION_FORM_URLENCODED.ToString())
            .AndExpect(MatchHeaderStartsWith("Authorization", "OAuth "))
            .AndExpectHeaderContains("Authorization", "oauth_version=\"1.0\"")
            .AndExpectHeaderContains("Authorization", "oauth_nonce=\"")
            .AndExpectHeaderContains("Authorization", "oauth_signature_method=\"HMAC-SHA1\"")
            .AndExpectHeaderContains("Authorization", "oauth_consumer_key=\"consumer_key\"")
            .AndExpectHeaderContains("Authorization", "oauth_token=\"access_token\"")
            .AndExpectHeaderContains("Authorization", "oauth_timestamp=\"")
            .AndExpectHeaderContains("Authorization", "oauth_signature=\"")
            .AndExpectBody("status=Hello+there%21");

            apiBinding.UpdateStatus();
        }