def test_raise_error_if_params_passed_but_signature_omitted(self):
     with self.assertRaises(haravan.ValidationException):
         session = haravan.Session("testshop.myharavan.com")
         token = session.request_token({
             'code': 'any_code',
             'foo': 'bar',
             'timestamp': '1234'
         })
    def test_raise_error_if_hmac_is_invalid(self):
        haravan.Session.secret='secret'
        params = {'code': 'any-code', 'timestamp': time.time()}
        params['hmac'] = 'a94a110d86d2452e92a4a64275b128e9273be3037f2c339eb3e2af4cfb8a3828'

        with self.assertRaises(haravan.ValidationException):
            session = haravan.Session('http://localhost.myharavan.com')
            session = session.request_token(params)
 def test_create_permission_url_returns_correct_url_with_single_scope_no_redirect_uri(
         self):
     haravan.Session.setup(api_key="My_test_key", secret="My test secret")
     session = haravan.Session('http://localhost.myharavan.com')
     scope = ["write_products"]
     permission_url = session.create_permission_url(scope)
     self.assertEqual(
         "https://localhost.myharavan.com/admin/oauth/authorize?client_id=My_test_key&scope=write_products",
         self.normalize_url(permission_url))
    def test_raise_exception_if_code_invalid_in_request_token(self):
        haravan.Session.setup(api_key="My test key", secret="My test secret")
        session = haravan.Session('http://localhost.myharavan.com')
        self.fake(None, url='https://localhost.myharavan.com/admin/oauth/access_token', method='POST', code=404, body='{"error" : "invalid_request"}', has_user_agent=False)

        with self.assertRaises(haravan.ValidationException):
            session.request_token({'code':'any-code', 'timestamp':'1234'})

        self.assertFalse(session.valid)
    def test_raise_error_if_timestamp_is_too_old(self):
        haravan.Session.secret = 'secret'
        one_day = 24 * 60 * 60
        params = {'code': 'any-code', 'timestamp': time.time() - (2 * one_day)}
        hmac = haravan.Session.calculate_hmac(params)
        params['hmac'] = hmac

        with self.assertRaises(haravan.ValidationException):
            session = haravan.Session('http://localhost.myharavan.com')
            session = session.request_token(params)
    def test_return_token_if_hmac_is_valid_but_signature_also_provided(self):
        haravan.Session.secret='secret'
        params = {'code': 'any-code', 'timestamp': time.time(), 'signature': '6e39a2'}
        hmac = haravan.Session.calculate_hmac(params)
        params['hmac'] = hmac

        self.fake(None, url='https://localhost.myharavan.com/admin/oauth/access_token', method='POST', body='{"access_token" : "token"}', has_user_agent=False)
        session = haravan.Session('http://localhost.myharavan.com')
        token = session.request_token(params)
        self.assertEqual("token", token)
Exemple #7
0
    def temp(cls, domain, token):
        import haravan
        original_domain = haravan.HaravanResource.get_site()
        original_token = haravan.HaravanResource.get_headers().get(
            'X-Haravan-Access-Token')
        original_session = haravan.Session(original_domain, original_token)

        session = Session(domain, token)
        haravan.HaravanResource.activate_session(session)
        yield
        haravan.HaravanResource.activate_session(original_session)
    def test_raise_error_if_hmac_does_not_match_expected(self):
        haravan.Session.secret = 'secret'
        params = {'foo': 'hello', 'timestamp': time.time()}
        hmac = haravan.Session.calculate_hmac(params)
        params['hmac'] = hmac
        params['bar'] = 'world'
        params['code'] = 'code'

        with self.assertRaises(haravan.ValidationException):
            session = haravan.Session('http://localhost.myharavan.com')
            session = session.request_token(params)
    def test_temp_reset_haravan_HaravanResource_site_to_original_value_when_using_a_non_standard_port(self):
        haravan.Session.setup(api_key="key", secret="secret")
        session1 = haravan.Session('fakeshop.myharavan.com:3000', 'token1')
        haravan.HaravanResource.activate_session(session1)

        assigned_site = ""
        with haravan.Session.temp("testshop.myharavan.com", "any-token"):
            assigned_site = haravan.HaravanResource.site

        self.assertEqual('https://testshop.myharavan.com/admin', assigned_site)
        self.assertEqual('https://fakeshop.myharavan.com:3000/admin', haravan.HaravanResource.site)
Exemple #10
0
 def setUpClass(self):
     self.session1 = haravan.Session('shop1.myharavan.com', 'token1')
     self.session2 = haravan.Session('shop2.myharavan.com', 'token2')
Exemple #11
0
 def _session_from_config(cls, config):
     session = haravan.Session(config.get("domain"))
     session.protocol = config.get("protocol", "https")
     session.api_key = config.get("api_key")
     session.token = config.get("password")
     return session
 def test_not_raise_error_without_params(self):
     session = haravan.Session("testshop.myharavan.com", "any-token")
 def test_be_valid_with_any_token_and_any_url(self):
     session = haravan.Session("testshop.myharavan.com", "any-token")
     self.assertTrue(session.valid)
 def test_not_be_valid_without_token(self):
     session = haravan.Session("testshop.myharavan.com")
     self.assertFalse(session.valid)
 def test_return_site_for_session(self):
     session = haravan.Session("testshop.myharavan.com", "any-token")
     self.assertEqual("https://testshop.myharavan.com/admin", session.site)
 def test_not_be_valid_without_a_url(self):
     session = haravan.Session("", "any-token")
     self.assertFalse(session.valid)