Esempio n. 1
0
class GoogleBaseAuthConnectionTest(GoogleTestCase):
    """
    Tests for GoogleBaseAuthConnection
    """

    def setUp(self):
        GoogleBaseAuthConnection.conn_class = GoogleAuthMockHttp
        self.mock_scopes = ['foo', 'bar']
        kwargs = {'scopes': self.mock_scopes}
        self.conn = GoogleInstalledAppAuthConnection(*GCE_PARAMS,
                                                     **kwargs)

    def test_scopes(self):
        self.assertEqual(self.conn.scopes, 'foo bar')

    def test_add_default_headers(self):
        old_headers = {}
        expected_headers = {
            'Content-Type': 'application/x-www-form-urlencoded',
            'Host': 'accounts.google.com'}
        new_headers = self.conn.add_default_headers(old_headers)
        self.assertEqual(new_headers, expected_headers)

    def test_token_request(self):
        request_body = {'code': 'asdf', 'client_id': self.conn.user_id,
                        'client_secret': self.conn.key,
                        'redirect_uri': self.conn.redirect_uri,
                        'grant_type': 'authorization_code'}
        new_token = self.conn._token_request(request_body)
        self.assertEqual(new_token['access_token'],
                         STUB_IA_TOKEN['access_token'])
        exp = STUB_UTCNOW + datetime.timedelta(
            seconds=STUB_IA_TOKEN['expires_in'])
        self.assertEqual(new_token['expire_time'], _utc_timestamp(exp))
Esempio n. 2
0
class GoogleInstalledAppAuthConnectionTest(GoogleTestCase):
    """
    Tests for GoogleInstalledAppAuthConnection
    """

    def setUp(self):
        GoogleInstalledAppAuthConnection.conn_class = GoogleAuthMockHttp
        self.mock_scopes = ['https://www.googleapis.com/auth/foo']
        kwargs = {'scopes': self.mock_scopes}
        self.conn = GoogleInstalledAppAuthConnection(*GCE_PARAMS,
                                                     **kwargs)

    def test_refresh_token(self):
        # This token info doesn't have a refresh token, so a new token will be
        # requested
        token_info1 = {'access_token': 'tokentoken', 'token_type': 'Bearer',
                       'expires_in': 3600}
        new_token1 = self.conn.refresh_token(token_info1)
        self.assertEqual(new_token1['access_token'],
                         STUB_IA_TOKEN['access_token'])

        # This token info has a refresh token, so it will be able to be
        # refreshed.
        token_info2 = {'access_token': 'tokentoken', 'token_type': 'Bearer',
                       'expires_in': 3600, 'refresh_token': 'refreshrefresh'}
        new_token2 = self.conn.refresh_token(token_info2)
        self.assertEqual(new_token2['access_token'],
                         STUB_REFRESH_TOKEN['access_token'])

        # Both sets should have refresh info
        self.assertTrue('refresh_token' in new_token1)
        self.assertTrue('refresh_token' in new_token2)
Esempio n. 3
0
class GoogleInstalledAppAuthConnectionTest(GoogleTestCase):
    """
    Tests for GoogleInstalledAppAuthConnection
    """

    def setUp(self):
        GoogleInstalledAppAuthConnection.conn_classes = (GoogleAuthMockHttp,
                                                         GoogleAuthMockHttp)
        self.mock_scopes = ['https://www.googleapis.com/auth/foo']
        kwargs = {'scopes': self.mock_scopes}
        self.conn = GoogleInstalledAppAuthConnection(*GCE_PARAMS,
                                                     **kwargs)

    def test_refresh_token(self):
        # This token info doesn't have a refresh token, so a new token will be
        # requested
        token_info1 = {'access_token': 'tokentoken', 'token_type': 'Bearer',
                       'expires_in': 3600}
        new_token1 = self.conn.refresh_token(token_info1)
        self.assertEqual(new_token1['access_token'],
                         STUB_IA_TOKEN['access_token'])

        # This token info has a refresh token, so it will be able to be
        # refreshed.
        token_info2 = {'access_token': 'tokentoken', 'token_type': 'Bearer',
                       'expires_in': 3600, 'refresh_token': 'refreshrefresh'}
        new_token2 = self.conn.refresh_token(token_info2)
        self.assertEqual(new_token2['access_token'],
                         STUB_REFRESH_TOKEN['access_token'])

        # Both sets should have refresh info
        self.assertTrue('refresh_token' in new_token1)
        self.assertTrue('refresh_token' in new_token2)
Esempio n. 4
0
 def setUp(self):
     GoogleInstalledAppAuthConnection.conn_classes = (GoogleAuthMockHttp,
                                                      GoogleAuthMockHttp)
     self.mock_scopes = ['https://www.googleapis.com/auth/foo']
     kwargs = {'scopes': self.mock_scopes}
     self.conn = GoogleInstalledAppAuthConnection(*GCE_PARAMS,
                                                  **kwargs)
Esempio n. 5
0
class GoogleBaseAuthConnectionTest(GoogleTestCase):
    """
    Tests for GoogleBaseAuthConnection
    """

    def setUp(self):
        GoogleBaseAuthConnection.conn_classes = (GoogleAuthMockHttp,
                                                 GoogleAuthMockHttp)
        self.mock_scopes = ['foo', 'bar']
        kwargs = {'scopes': self.mock_scopes}
        self.conn = GoogleInstalledAppAuthConnection(*GCE_PARAMS,
                                                     **kwargs)

    def test_scopes(self):
        self.assertEqual(self.conn.scopes, 'foo bar')

    def test_add_default_headers(self):
        old_headers = {}
        expected_headers = {
            'Content-Type': 'application/x-www-form-urlencoded',
            'Host': 'accounts.google.com'}
        new_headers = self.conn.add_default_headers(old_headers)
        self.assertEqual(new_headers, expected_headers)

    def test_token_request(self):
        request_body = {'code': 'asdf', 'client_id': self.conn.user_id,
                        'client_secret': self.conn.key,
                        'redirect_uri': self.conn.redirect_uri,
                        'grant_type': 'authorization_code'}
        new_token = self.conn._token_request(request_body)
        self.assertEqual(new_token['access_token'],
                         STUB_IA_TOKEN['access_token'])
        exp = STUB_UTCNOW + datetime.timedelta(
            seconds=STUB_IA_TOKEN['expires_in'])
        self.assertEqual(new_token['expire_time'], _utc_timestamp(exp))
Esempio n. 6
0
 def setUp(self):
     GoogleBaseAuthConnection.conn_classes = (GoogleAuthMockHttp,
                                              GoogleAuthMockHttp)
     self.mock_scopes = ['foo', 'bar']
     kwargs = {'scopes': self.mock_scopes}
     self.conn = GoogleInstalledAppAuthConnection(*GCE_PARAMS,
                                                  **kwargs)
Esempio n. 7
0
class GoogleBaseAuthConnectionTest(LibcloudTestCase):
    """
    Tests for GoogleBaseAuthConnection
    """
    GoogleBaseAuthConnection._now = lambda x: datetime.datetime(
        2013, 6, 26, 19, 0, 0)

    def setUp(self):
        GoogleBaseAuthConnection.conn_classes = (GoogleAuthMockHttp,
                                                 GoogleAuthMockHttp)
        self.mock_scope = ['https://www.googleapis.com/auth/foo']
        kwargs = {'scope': self.mock_scope}
        self.conn = GoogleInstalledAppAuthConnection(*GCE_PARAMS, **kwargs)

    def test_add_default_headers(self):
        old_headers = {}
        expected_headers = {
            'Content-Type': 'application/x-www-form-urlencoded',
            'Host': 'accounts.google.com'
        }
        new_headers = self.conn.add_default_headers(old_headers)
        self.assertEqual(new_headers, expected_headers)

    def test_token_request(self):
        request_body = {
            'code': 'asdf',
            'client_id': self.conn.user_id,
            'client_secret': self.conn.key,
            'redirect_uri': self.conn.redirect_uri,
            'grant_type': 'authorization_code'
        }
        new_token = self.conn._token_request(request_body)
        self.assertEqual(new_token['access_token'], 'installedapp')
        self.assertEqual(new_token['expire_time'], '2013-06-26T20:00:00Z')
Esempio n. 8
0
class GoogleBaseAuthConnectionTest(LibcloudTestCase):
    """
    Tests for GoogleBaseAuthConnection
    """
    GoogleBaseAuthConnection._now = lambda x: datetime.datetime(2013, 6, 26,
                                                                19, 0, 0)

    def setUp(self):
        GoogleBaseAuthConnection.conn_classes = (GoogleAuthMockHttp,
                                                 GoogleAuthMockHttp)
        self.mock_scopes = ['foo', 'bar']
        kwargs = {'scopes': self.mock_scopes}
        self.conn = GoogleInstalledAppAuthConnection(*GCE_PARAMS,
                                                     **kwargs)

    def test_scopes(self):
        self.assertEqual(self.conn.scopes, 'foo bar')

    def test_add_default_headers(self):
        old_headers = {}
        expected_headers = {
            'Content-Type': 'application/x-www-form-urlencoded',
            'Host': 'accounts.google.com'}
        new_headers = self.conn.add_default_headers(old_headers)
        self.assertEqual(new_headers, expected_headers)

    def test_token_request(self):
        request_body = {'code': 'asdf', 'client_id': self.conn.user_id,
                        'client_secret': self.conn.key,
                        'redirect_uri': self.conn.redirect_uri,
                        'grant_type': 'authorization_code'}
        new_token = self.conn._token_request(request_body)
        self.assertEqual(new_token['access_token'], 'installedapp')
        self.assertEqual(new_token['expire_time'], '2013-06-26T20:00:00Z')
class GoogleBaseAuthConnectionTest(LibcloudTestCase):
    """
    Tests for GoogleBaseAuthConnection
    """

    GoogleBaseAuthConnection._now = lambda x: datetime.datetime(2013, 6, 26, 19, 0, 0)

    def setUp(self):
        GoogleBaseAuthConnection.conn_classes = (GoogleAuthMockHttp, GoogleAuthMockHttp)
        self.mock_scopes = ["foo", "bar"]
        kwargs = {"scopes": self.mock_scopes}
        self.conn = GoogleInstalledAppAuthConnection(*GCE_PARAMS, **kwargs)

    def test_scopes(self):
        self.assertEqual(self.conn.scopes, "foo bar")

    def test_add_default_headers(self):
        old_headers = {}
        expected_headers = {"Content-Type": "application/x-www-form-urlencoded", "Host": "accounts.google.com"}
        new_headers = self.conn.add_default_headers(old_headers)
        self.assertEqual(new_headers, expected_headers)

    def test_token_request(self):
        request_body = {
            "code": "asdf",
            "client_id": self.conn.user_id,
            "client_secret": self.conn.key,
            "redirect_uri": self.conn.redirect_uri,
            "grant_type": "authorization_code",
        }
        new_token = self.conn._token_request(request_body)
        self.assertEqual(new_token["access_token"], "installedapp")
        self.assertEqual(new_token["expire_time"], "2013-06-26T20:00:00Z")
class GoogleInstalledAppAuthConnectionTest(LibcloudTestCase):
    """
    Tests for GoogleInstalledAppAuthConnection
    """

    GoogleInstalledAppAuthConnection.get_code = lambda x: "1234"

    def setUp(self):
        GoogleInstalledAppAuthConnection.conn_classes = (GoogleAuthMockHttp, GoogleAuthMockHttp)
        self.mock_scopes = ["https://www.googleapis.com/auth/foo"]
        kwargs = {"scopes": self.mock_scopes}
        self.conn = GoogleInstalledAppAuthConnection(*GCE_PARAMS, **kwargs)

    def test_refresh_token(self):
        # This token info doesn't have a refresh token, so a new token will be
        # requested
        token_info1 = {"access_token": "tokentoken", "token_type": "Bearer", "expires_in": 3600}
        new_token1 = self.conn.refresh_token(token_info1)
        self.assertEqual(new_token1["access_token"], "installedapp")

        # This token info has a refresh token, so it will be able to be
        # refreshed.
        token_info2 = {
            "access_token": "tokentoken",
            "token_type": "Bearer",
            "expires_in": 3600,
            "refresh_token": "refreshrefresh",
        }
        new_token2 = self.conn.refresh_token(token_info2)
        self.assertEqual(new_token2["access_token"], "refreshrefresh")

        # Both sets should have refresh info
        self.assertTrue("refresh_token" in new_token1)
        self.assertTrue("refresh_token" in new_token2)
Esempio n. 11
0
class GoogleInstalledAppAuthConnectionTest(GoogleTestCase):
    """
    Tests for GoogleInstalledAppAuthConnection
    """
    def setUp(self):
        GoogleInstalledAppAuthConnection.conn_class = GoogleAuthMockHttp
        self.mock_scopes = ["https://www.googleapis.com/auth/foo"]
        kwargs = {"scopes": self.mock_scopes}
        self.conn = GoogleInstalledAppAuthConnection(*GCE_PARAMS, **kwargs)

    def test_refresh_token(self):
        # This token info doesn't have a refresh token, so a new token will be
        # requested
        token_info1 = {
            "access_token": "tokentoken",
            "token_type": "Bearer",
            "expires_in": 3600,
        }
        new_token1 = self.conn.refresh_token(token_info1)
        self.assertEqual(new_token1["access_token"],
                         STUB_IA_TOKEN["access_token"])

        # This token info has a refresh token, so it will be able to be
        # refreshed.
        token_info2 = {
            "access_token": "tokentoken",
            "token_type": "Bearer",
            "expires_in": 3600,
            "refresh_token": "refreshrefresh",
        }
        new_token2 = self.conn.refresh_token(token_info2)
        self.assertEqual(new_token2["access_token"],
                         STUB_REFRESH_TOKEN["access_token"])

        # Both sets should have refresh info
        self.assertTrue("refresh_token" in new_token1)
        self.assertTrue("refresh_token" in new_token2)
Esempio n. 12
0
class GoogleBaseAuthConnectionTest(GoogleTestCase):
    """
    Tests for GoogleBaseAuthConnection
    """
    def setUp(self):
        GoogleBaseAuthConnection.conn_class = GoogleAuthMockHttp
        self.mock_scopes = ["foo", "bar"]
        kwargs = {"scopes": self.mock_scopes}
        self.conn = GoogleInstalledAppAuthConnection(*GCE_PARAMS, **kwargs)

    def test_scopes(self):
        self.assertEqual(self.conn.scopes, "foo bar")

    def test_add_default_headers(self):
        old_headers = {}
        expected_headers = {
            "Content-Type": "application/x-www-form-urlencoded",
            "Host": "accounts.google.com",
        }
        new_headers = self.conn.add_default_headers(old_headers)
        self.assertEqual(new_headers, expected_headers)

    def test_token_request(self):
        request_body = {
            "code": "asdf",
            "client_id": self.conn.user_id,
            "client_secret": self.conn.key,
            "redirect_uri": self.conn.redirect_uri,
            "grant_type": "authorization_code",
        }
        new_token = self.conn._token_request(request_body)
        self.assertEqual(new_token["access_token"],
                         STUB_IA_TOKEN["access_token"])
        exp = STUB_UTCNOW + datetime.timedelta(
            seconds=STUB_IA_TOKEN["expires_in"])
        self.assertEqual(new_token["expire_time"], _utc_timestamp(exp))
 def setUp(self):
     GoogleBaseAuthConnection.conn_classes = (GoogleAuthMockHttp, GoogleAuthMockHttp)
     self.mock_scopes = ["foo", "bar"]
     kwargs = {"scopes": self.mock_scopes}
     self.conn = GoogleInstalledAppAuthConnection(*GCE_PARAMS, **kwargs)
Esempio n. 14
0
 def setUp(self):
     GoogleInstalledAppAuthConnection.conn_class = GoogleAuthMockHttp
     self.mock_scopes = ["https://www.googleapis.com/auth/foo"]
     kwargs = {"scopes": self.mock_scopes}
     self.conn = GoogleInstalledAppAuthConnection(*GCE_PARAMS, **kwargs)
Esempio n. 15
0
 def setUp(self):
     GoogleBaseAuthConnection.conn_class = GoogleAuthMockHttp
     self.mock_scopes = ["foo", "bar"]
     kwargs = {"scopes": self.mock_scopes}
     self.conn = GoogleInstalledAppAuthConnection(*GCE_PARAMS, **kwargs)