def test_sign_with_discovered_service_account(self): request = testutils.MockRequest(200, 'discovered-service-account') app = firebase_admin.initialize_app(testutils.MockCredential(), name='iam-signer-app') try: _overwrite_iam_request(app, request) # Force initialization of the signing provider. This will invoke the Metadata service. auth_service = auth._get_auth_service(app) assert auth_service.token_generator.signing_provider is not None # Now invoke the IAM signer. signature = base64.b64encode(b'test').decode() request.response = testutils.MockResponse( 200, '{{"signature": "{0}"}}'.format(signature)) custom_token = auth.create_custom_token(MOCK_UID, app=app).decode() assert custom_token.endswith('.' + signature) self._verify_signer(custom_token, 'discovered-service-account') assert len(request.log) == 2 assert request.log[0][1]['headers'] == { 'Metadata-Flavor': 'Google' } finally: firebase_admin.delete_app(app)
def test_listen_error(self): test_url = 'https://test.firebaseio.com' firebase_admin.initialize_app(testutils.MockCredential(), { 'databaseURL': test_url, }) try: ref = db.reference() adapter = MockAdapter(json.dumps({'error': 'json error message'}), 500, []) session = ref._client.session session.mount(test_url, adapter) def callback(_): pass with pytest.raises(exceptions.InternalError) as excinfo: ref._listen_with_session(callback, session) assert str(excinfo.value) == 'json error message' assert excinfo.value.cause is not None assert excinfo.value.http_response is not None finally: testutils.cleanup_apps()
def test_valid_db_url(self, url): firebase_admin.initialize_app(testutils.MockCredential(), {'databaseURL': url}) ref = db.reference() assert ref._client.base_url == 'https://test.firebaseio.com' assert ref._client.auth_override is None
def evaluate(): firebase_admin.initialize_app(testutils.MockCredential()) with pytest.raises(ValueError): firestore.client()
def setup_class(cls): cred = testutils.MockCredential() firebase_admin.initialize_app(cred, {'projectId': 'explicit-project-id'})
def test_fail_on_no_project_id(self): app = firebase_admin.initialize_app(testutils.MockCredential(), name='userMgt2') with pytest.raises(ValueError): auth._get_auth_service(app) firebase_admin.delete_app(app)
def evaluate(): firebase_admin.initialize_app(testutils.MockCredential()) with pytest.raises(ValueError): instance_id.delete_instance_id('test')
def setup_class(cls): firebase_admin.initialize_app(testutils.MockCredential(), { 'databaseURL' : cls.test_url, 'databaseAuthVariableOverride' : {'uid':'user1'} })
def setup_class(cls): cred = testutils.MockCredential() firebase_admin.initialize_app(cred, {'projectId': PROJECT_ID})
def evaluate(): app = firebase_admin.initialize_app(testutils.MockCredential(), name='no_project_id') with pytest.raises(ValueError): ml.delete_model(MODEL_ID_1, app)
def setup_class(cls): cred = testutils.MockCredential() firebase_admin.initialize_app(cred, {'projectId': PROJECT_ID}) ml._MLService.POLL_BASE_WAIT_TIME_SECONDS = 0.1 # shorter for test
def setup_class(cls): cred = testutils.MockCredential() firebase_admin.initialize_app(cred, {'projectId': PROJECT_ID}) ml._MLService.POLL_BASE_WAIT_TIME_SECONDS = 0.1 # shorter for test ml.TFLiteGCSModelSource._STORAGE_CLIENT = _TestStorageClient()
def evaluate(): app = firebase_admin.initialize_app(testutils.MockCredential(), name='no_project_id') with pytest.raises(ValueError): ml.list_models(app=app)
def test_invalid_db_url(self, url): firebase_admin.initialize_app(testutils.MockCredential(), {'databaseURL' : url}) with pytest.raises(ValueError): db.reference()
def test_default_timeout(self): cred = testutils.MockCredential() app = firebase_admin.initialize_app( cred, {'projectId': 'explicit-project-id'}) iid_service = instance_id._get_iid_service(app) assert iid_service._client.timeout == _http_client.DEFAULT_TIMEOUT_SECONDS
def setup_class(cls): firebase_admin.initialize_app(testutils.MockCredential(), {'databaseURL' : cls.test_url})
def evaluate(): app = firebase_admin.initialize_app(testutils.MockCredential(), name='myApp') assert app.project_id is None
def test_no_db_url(self): firebase_admin.initialize_app(testutils.MockCredential()) with pytest.raises(ValueError): db.reference()
def user_mgt_app(): app = firebase_admin.initialize_app(testutils.MockCredential(), name='userMgt', options={'projectId': 'mock-project-id'}) yield app firebase_admin.delete_app(app)
def user_mgt_app(): app = firebase_admin.initialize_app(testutils.MockCredential(), name='userMgt') yield app firebase_admin.delete_app(app)
def evaluate(): app = firebase_admin.initialize_app(testutils.MockCredential(), name='no_project_id') with pytest.raises(ValueError): messaging.send(messaging.Message(topic='foo'), app=app)