Beispiel #1
0
    def test_auth_type(self):
        self.assertRaises(GoogleAuthError, GoogleBaseConnection, *GCE_PARAMS,
                          **{'auth_type': 'XX'})

        kwargs = {'scopes': self.mock_scopes}

        if SHA256:
            kwargs['auth_type'] = 'SA'
            conn1 = GoogleBaseConnection(*GCE_PARAMS_PEM_KEY, **kwargs)
            self.assertTrue(
                isinstance(conn1.auth_conn, GoogleServiceAcctAuthConnection))

            conn1 = GoogleBaseConnection(*GCE_PARAMS_JSON_KEY, **kwargs)
            self.assertTrue(
                isinstance(conn1.auth_conn, GoogleServiceAcctAuthConnection))

            conn1 = GoogleBaseConnection(*GCE_PARAMS_KEY, **kwargs)
            self.assertTrue(
                isinstance(conn1.auth_conn, GoogleServiceAcctAuthConnection))

        kwargs['auth_type'] = 'IA'
        conn2 = GoogleBaseConnection(*GCE_PARAMS_IA, **kwargs)
        self.assertTrue(
            isinstance(conn2.auth_conn, GoogleInstalledAppAuthConnection))

        kwargs['auth_type'] = 'GCE'
        conn3 = GoogleBaseConnection(*GCE_PARAMS_GCE, **kwargs)
        self.assertTrue(
            isinstance(conn3.auth_conn, GoogleGCEServiceAcctAuthConnection))
Beispiel #2
0
 def setUp(self):
     GoogleBaseAuthConnection.conn_classes = (GoogleAuthMockHttp,
                                              GoogleAuthMockHttp)
     self.mock_scopes = ['https://www.googleapis.com/auth/foo']
     kwargs = {'scopes': self.mock_scopes,
               'auth_type': GoogleAuthType.IA}
     self.conn = GoogleBaseConnection(*GCE_PARAMS, **kwargs)
Beispiel #3
0
    def test_init_oauth2(self):
        mock_scopes = ['https://www.googleapis.com/auth/foo']
        kwargs = {'scopes': mock_scopes,
                  'auth_type': GoogleAuthType.IA}
        conn = GoogleBaseConnection(*GCE_PARAMS, **kwargs)

        # If there is a viable token file, this gets used first
        self.assertEqual(conn.oauth2_token, STUB_TOKEN_FROM_FILE)

        # No token file, get a new token. Check that it gets written to file.
        with mock.patch.object(GoogleBaseConnection,
                               '_get_token_from_file', return_value=None):
            conn = GoogleBaseConnection(*GCE_PARAMS, **kwargs)
            expected = STUB_IA_TOKEN
            expected['expire_time'] = conn.oauth2_token['expire_time']
            self.assertEqual(conn.oauth2_token, expected)
            conn._write_token_to_file.assert_called_once_with()
Beispiel #4
0
    def test_auth_type(self):
        self.assertRaises(GoogleAuthError, GoogleBaseConnection, *GCE_PARAMS,
                          **{'auth_type': 'XX'})

        kwargs = {'scopes': self.mock_scopes}

        if SHA256:
            kwargs['auth_type'] = GoogleAuthType.SA
            conn1 = GoogleBaseConnection(*GCE_PARAMS_PEM_KEY, **kwargs)
            self.assertTrue(isinstance(conn1.oauth2_conn,
                                       GoogleServiceAcctAuthConnection))

            conn1 = GoogleBaseConnection(*GCE_PARAMS_JSON_KEY, **kwargs)
            self.assertTrue(isinstance(conn1.oauth2_conn,
                                       GoogleServiceAcctAuthConnection))

            conn1 = GoogleBaseConnection(*GCE_PARAMS_KEY, **kwargs)
            self.assertTrue(isinstance(conn1.oauth2_conn,
                                       GoogleServiceAcctAuthConnection))

        kwargs['auth_type'] = GoogleAuthType.IA
        conn2 = GoogleBaseConnection(*GCE_PARAMS_IA, **kwargs)
        self.assertTrue(isinstance(conn2.oauth2_conn,
                                   GoogleInstalledAppAuthConnection))

        kwargs['auth_type'] = GoogleAuthType.GCE
        conn3 = GoogleBaseConnection(*GCE_PARAMS_GCE, **kwargs)
        self.assertTrue(isinstance(conn3.oauth2_conn,
                                   GoogleGCEServiceAcctAuthConnection))

        kwargs['auth_type'] = GoogleAuthType.GCS_S3
        conn4 = GoogleBaseConnection(*GCS_S3_PARAMS, **kwargs)
        self.assertIsNone(conn4.oauth2_conn)
Beispiel #5
0
 def setUp(self):
     GoogleBaseAuthConnection.conn_class = GoogleAuthMockHttp
     self.mock_scopes = ["https://www.googleapis.com/auth/foo"]
     kwargs = {"scopes": self.mock_scopes, "auth_type": GoogleAuthType.IA}
     self.conn = GoogleBaseConnection(*GCE_PARAMS, **kwargs)