Example #1
0
 def login(self, resp_mock, process='login', with_refresh_token=True):
     resp = self.client.get(reverse(self.provider.id + '_login'), {
         'process': process,
         'shop': 'test'
     })
     self.assertEqual(resp.status_code, 200)  # No re-direct, JS must do it
     actual_content = resp.content.decode('utf8')
     self.assertTrue(
         'script' in actual_content,
         'Content missing script tag. [Actual: {}]'.format(actual_content))
     self.assertTrue(
         resp.xframe_options_exempt,
         'Redirect JS must be allowed to run in Shopify iframe')
     self.assertTrue(
         '<!DOCTYPE html><html><head>' in actual_content
         and '</head><body></body></html>' in actual_content,
         'Expected standard HTML skeleton. [Actual: {}]'.format(
             actual_content))
     p = urlparse(
         actual_content.split(";</script>")[0].split('location.href = "')
         [1])
     q = parse_qs(p.query)
     resp = self._complete_shopify_login(q, resp, resp_mock,
                                         with_refresh_token)
     return resp
Example #2
0
 def login(self, resp_mock, process='login', with_refresh_token=True):
     resp = self.client.get(reverse(self.provider.id + '_login'),
                            {'process': process, 'shop': 'test'})
     self.assertEqual(resp.status_code, 302)
     p = urlparse(resp['location'])
     q = parse_qs(p.query)
     resp = self._complete_shopify_login(q, resp, resp_mock,
                                         with_refresh_token)
     return resp
Example #3
0
 def login(self, resp_mock, process='login', with_refresh_token=True):
     resp = self.client.get(reverse(self.provider.id + '_login'),
                            {'process': process, 'shop': 'test'})
     self.assertEqual(resp.status_code, 302)
     p = urlparse(resp['location'])
     q = parse_qs(p.query)
     resp = self._complete_shopify_login(q, resp, resp_mock,
                                         with_refresh_token)
     return resp
Example #4
0
def get_token_prefix(url):
    """
    Returns a prefix for the token to store in the session so we can hold
    more than one single oauth provider's access key in the session.

    Example:

        The request token url ``http://twitter.com/oauth/request_token``
        returns ``twitter.com``

    """
    return urlparse(url).netloc
Example #5
0
def get_token_prefix(url):
    """
    Returns a prefix for the token to store in the session so we can hold
    more than one single oauth provider's access key in the session.

    Example:

        The request token url ``http://twitter.com/oauth/request_token``
        returns ``twitter.com``

    """
    return urlparse(url).netloc
Example #6
0
 def get_brand(self):
     ret = super(OpenIDAccount, self).get_brand()
     domain = urlparse(self.account.uid).netloc
     # FIXME: Instead of hardcoding, derive this from the domains
     # listed in the openid endpoints setting.
     provider_map = {
         'yahoo': dict(id='yahoo', name='Yahoo'),
         'hyves': dict(id='hyves', name='Hyves'),
         'google': dict(id='google', name='Google')
     }
     for d, p in provider_map.items():
         if domain.lower().find(d) >= 0:
             ret = p
             break
     return ret
Example #7
0
 def get_brand(self):
     ret = super(OpenIDAccount, self).get_brand()
     domain = urlparse(self.account.uid).netloc
     # FIXME: Instead of hardcoding, derive this from the domains
     # listed in the openid endpoints setting.
     provider_map = {'yahoo': dict(id='yahoo',
                                   name='Yahoo'),
                     'hyves': dict(id='hyves',
                                   name='Hyves'),
                     'google': dict(id='google',
                                    name='Google')}
     for d, p in provider_map.items():
         if domain.lower().find(d) >= 0:
             ret = p
             break
     return ret
Example #8
0
 def login(self, resp_mock, process='login', with_refresh_token=True):
     resp = self.client.get(reverse(self.provider.id + '_login'), {
         'process': process,
         'shop': 'test'
     })
     p = urlparse(resp['location'])
     q = parse_qs(p.query)
     complete_url = reverse(self.provider.id + '_callback')
     self.assertGreater(q['redirect_uri'][0].find(complete_url), 0)
     response_json = self \
         .get_login_response_json(with_refresh_token=with_refresh_token)
     with mocked_response(
             MockedResponse(200, response_json,
                            {'content-type': 'application/json'}),
             resp_mock):
         resp = self.client.get(complete_url, {
             'code': 'test',
             'state': q['state'][0],
             'shop': 'test',
         })
     return resp
Example #9
0
 def login(self, resp_mock, process='login', with_refresh_token=True):
     resp = self.client.get(reverse(self.provider.id + '_login'),
                            {'process': process, 'shop': 'test'})
     p = urlparse(resp['location'])
     q = parse_qs(p.query)
     complete_url = reverse(self.provider.id+'_callback')
     self.assertGreater(q['redirect_uri'][0]
                        .find(complete_url), 0)
     response_json = self \
         .get_login_response_json(with_refresh_token=with_refresh_token)
     with mocked_response(
             MockedResponse(
                 200,
                 response_json,
                 {'content-type': 'application/json'}),
             resp_mock):
         resp = self.client.get(complete_url,
                                {'code': 'test',
                                 'state': q['state'][0],
                                 'shop': 'test',
                                 })
     return resp
Example #10
0
 def login(self, resp_mock, process='login', with_refresh_token=True):
     resp = self.client.get(reverse(self.provider.id + '_login'),
                            {'process': process, 'shop': 'test'})
     self.assertEqual(resp.status_code, 200)  # No re-direct, JS must do it
     actual_content = resp.content.decode('utf8')
     self.assertTrue('script' in actual_content,
                     'Content missing script tag. [Actual: {}]'.format(
                         actual_content))
     self.assertTrue(resp.xframe_options_exempt,
                     'Redirect JS must be allowed to run in Shopify iframe')
     self.assertTrue(
         '<!DOCTYPE html><html><head>' in actual_content and
         '</head><body></body></html>' in actual_content,
         'Expected standard HTML skeleton. [Actual: {}]'.format(
             actual_content
         )
     )
     p = urlparse(actual_content.split(";</script>")[0].split(
         'location.href = "')[1])
     q = parse_qs(p.query)
     resp = self._complete_shopify_login(q, resp, resp_mock,
                                         with_refresh_token)
     return resp