Java Code Examples for com.google.firebase.auth.FirebaseAuth#signOut()

The following examples show how to use com.google.firebase.auth.FirebaseAuth#signOut() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StorageTest.java    From firebase-android-sdk with Apache License 2.0 6 votes vote down vote up
@Test
public void putShouldFailWithNotAuthorized() throws Exception {
  FirebaseAuth auth = FirebaseAuth.getInstance();
  FirebaseStorage storage = FirebaseStorage.getInstance();

  auth.signOut();
  StorageReference blob = storage.getReference("restaurants").child(TestId.create());
  byte[] data = "Google NYC".getBytes(StandardCharsets.UTF_8);

  try {
    Task<?> putTask = blob.putBytes(Arrays.copyOf(data, data.length));
    Throwable failure = Tasks2.waitForFailure(putTask);
    StorageException ex = (StorageException) failure;
    assertThat(ex.getErrorCode()).isEqualTo(StorageException.ERROR_NOT_AUTHORIZED);
  } finally {
    Tasks2.waitBestEffort(blob.delete());
  }
}
 
Example 2
Source File: StorageTest.java    From firebase-android-sdk with Apache License 2.0 6 votes vote down vote up
@Test
public void getShouldReturnNewlyPutData() throws Exception {
  FirebaseAuth auth = FirebaseAuth.getInstance();
  FirebaseStorage storage = FirebaseStorage.getInstance();

  auth.signOut();
  Task<?> signInTask = auth.signInWithEmailAndPassword("[email protected]", "password");
  Tasks2.waitForSuccess(signInTask);

  StorageReference blob = storage.getReference("restaurants").child(TestId.create());

  byte[] data = "Google NYC".getBytes(StandardCharsets.UTF_8);

  try {
    Task<?> putTask = blob.putBytes(Arrays.copyOf(data, data.length));
    Tasks2.waitForSuccess(putTask);

    Task<byte[]> getTask = blob.getBytes(128);
    Tasks2.waitForSuccess(getTask);

    byte[] result = getTask.getResult();
    assertThat(result).isEqualTo(data);
  } finally {
    Tasks2.waitBestEffort(blob.delete());
  }
}
 
Example 3
Source File: DatabaseTest.java    From firebase-android-sdk with Apache License 2.0 6 votes vote down vote up
@Test
public void setValueShouldFailWithPermissionDenied() throws Exception {
  FirebaseAuth auth = FirebaseAuth.getInstance();
  FirebaseDatabase database = FirebaseDatabase.getInstance();

  auth.signOut();
  Thread.sleep(1000); // TODO(allisonbm92): Introduce a better way to reduce flakiness.
  DatabaseReference doc = database.getReference("restaurants").child(TestId.create());
  HashMap<String, Object> data = new HashMap<>();
  data.put("location", "Google DUB");

  try {
    Task<?> setTask = doc.setValue(new HashMap<>(data));
    Tasks2.waitForFailure(setTask);

    // Unfortunately, there's no good way to test that this has the correct error code, because
    // Database does not expose it through the task interface. Perhaps we could re-structure this
    // in the future.
  } finally {
    Tasks2.waitBestEffort(doc.removeValue());
  }
}
 
Example 4
Source File: FirestoreTest.java    From firebase-android-sdk with Apache License 2.0 6 votes vote down vote up
@Test
public void setShouldFailWithPermissionDenied() throws Exception {
  FirebaseAuth auth = FirebaseAuth.getInstance();
  FirebaseFirestore firestore = FirebaseFirestore.getInstance();

  auth.signOut();
  Thread.sleep(1000); // TODO(allisonbm92): Introduce a better means to reduce flakes.
  DocumentReference doc = firestore.collection("restaurants").document(TestId.create());
  try {
    HashMap<String, Object> data = new HashMap<>();
    data.put("popularity", 5000L);

    Task<?> setTask = doc.set(new HashMap<>(data));
    Throwable failure = Tasks2.waitForFailure(setTask);
    FirebaseFirestoreException ex = (FirebaseFirestoreException) failure;

    assertThat(ex.getCode()).isEqualTo(FirebaseFirestoreException.Code.PERMISSION_DENIED);
  } finally {
    Tasks2.waitBestEffort(doc.delete());
  }
}
 
Example 5
Source File: HomeActivity.java    From MangoBloggerAndroidApp with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
    int id = item.getItemId();

    if(id == R.id.nav_signOut) {
        PreferenceUtil.signOut(this);
        FirebaseAuth mAuth = FirebaseAuth.getInstance();
        if(mAuth.getCurrentUser() != null) {
            mAuth.signOut();
        }
        startActivity(new Intent(this, LoginActivity.class));
        finish();
    }
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}
 
Example 6
Source File: DatabaseTest.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
@Test
public void setValueShouldTriggerListenerWithNewlySetData() throws Exception {
  FirebaseAuth auth = FirebaseAuth.getInstance();
  FirebaseDatabase database = FirebaseDatabase.getInstance();

  auth.signOut();
  Task<?> signInTask = auth.signInWithEmailAndPassword("[email protected]", "password");
  Tasks2.waitForSuccess(signInTask);

  DatabaseReference doc = database.getReference("restaurants").child(TestId.create());
  SnapshotListener listener = new SnapshotListener();
  doc.addListenerForSingleValueEvent(listener);

  HashMap<String, Object> data = new HashMap<>();
  data.put("location", "Google NYC");

  try {
    Task<?> setTask = doc.setValue(new HashMap<>(data));
    Task<DataSnapshot> snapshotTask = listener.toTask();
    Tasks2.waitForSuccess(setTask);
    Tasks2.waitForSuccess(snapshotTask);

    DataSnapshot result = snapshotTask.getResult();
    assertThat(result.getValue()).isEqualTo(data);
  } finally {
    Tasks2.waitBestEffort(doc.removeValue());
  }
}
 
Example 7
Source File: DatabaseTest.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
@Test
public void updateChildrenShouldTriggerListenerWithUpdatedData() throws Exception {
  FirebaseAuth auth = FirebaseAuth.getInstance();
  FirebaseDatabase database = FirebaseDatabase.getInstance();

  auth.signOut();
  Task<?> signInTask = auth.signInWithEmailAndPassword("[email protected]", "password");
  Tasks2.waitForSuccess(signInTask);

  DatabaseReference doc = database.getReference("restaurants").child(TestId.create());
  HashMap<String, Object> originalData = new HashMap<>();
  originalData.put("location", "Google NYC");

  try {
    Task<?> setTask = doc.setValue(new HashMap<>(originalData));
    Tasks2.waitForSuccess(setTask);
    SnapshotListener listener = new SnapshotListener();
    doc.addListenerForSingleValueEvent(listener);

    HashMap<String, Object> updateData = new HashMap<>();
    updateData.put("count", 412L);

    Task<?> updateTask = doc.updateChildren(new HashMap<>(updateData));
    Task<DataSnapshot> snapshotTask = listener.toTask();
    Tasks2.waitForSuccess(updateTask);
    Tasks2.waitForSuccess(snapshotTask);

    DataSnapshot result = snapshotTask.getResult();
    HashMap<String, Object> finalData = new HashMap<>();
    finalData.put("location", "Google NYC");
    finalData.put("count", 412L);
    assertThat(result.getValue()).isEqualTo(finalData);
  } finally {
    Tasks2.waitBestEffort(doc.removeValue());
  }
}
 
Example 8
Source File: FirestoreTest.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
@Test
public void setShouldTriggerListenerWithNewlySetData() throws Exception {
  FirebaseAuth auth = FirebaseAuth.getInstance();
  FirebaseFirestore firestore = FirebaseFirestore.getInstance();

  auth.signOut();
  Task<?> signInTask = auth.signInWithEmailAndPassword("[email protected]", "password");
  Tasks2.waitForSuccess(signInTask);

  DocumentReference doc = firestore.collection("restaurants").document(TestId.create());
  SnapshotListener listener = new SnapshotListener();
  ListenerRegistration registration = doc.addSnapshotListener(listener);

  try {
    HashMap<String, Object> data = new HashMap<>();
    data.put("location", "Google NYC");

    Task<?> setTask = doc.set(new HashMap<>(data));
    Task<DocumentSnapshot> snapshotTask = listener.toTask();
    Tasks2.waitForSuccess(setTask);
    Tasks2.waitForSuccess(snapshotTask);

    DocumentSnapshot result = snapshotTask.getResult();
    assertThat(result.getData()).isEqualTo(data);
  } finally {
    registration.remove();
    Tasks2.waitBestEffort(doc.delete());
  }
}
 
Example 9
Source File: FirestoreTest.java    From firebase-android-sdk with Apache License 2.0 4 votes vote down vote up
@Test
public void updateShouldTriggerListenerWithUpdatedData() throws Exception {
  FirebaseAuth auth = FirebaseAuth.getInstance();
  FirebaseFirestore firestore = FirebaseFirestore.getInstance();

  auth.signOut();
  Task<?> signInTask = auth.signInWithEmailAndPassword("[email protected]", "password");
  Tasks2.waitForSuccess(signInTask);

  DocumentReference doc = firestore.collection("restaurants").document(TestId.create());
  try {
    HashMap<String, Object> originalData = new HashMap<>();
    originalData.put("location", "Google NYC");

    Task<?> setTask = doc.set(new HashMap<>(originalData));
    Tasks2.waitForSuccess(setTask);

    SnapshotListener listener = new SnapshotListener(2);
    ListenerRegistration registration = doc.addSnapshotListener(listener);

    try {
      HashMap<String, Object> updateData = new HashMap<>();
      updateData.put("priority", 5L);

      Task<?> updateTask = doc.update(new HashMap<>(updateData));
      Task<DocumentSnapshot> snapshotTask = listener.toTask();
      Tasks2.waitForSuccess(updateTask);
      Tasks2.waitForSuccess(snapshotTask);

      DocumentSnapshot result = snapshotTask.getResult();
      HashMap<String, Object> finalData = new HashMap<>();
      finalData.put("location", "Google NYC");
      finalData.put("priority", 5L);
      assertThat(result.getData()).isEqualTo(finalData);
    } finally {
      registration.remove();
    }
  } finally {
    Tasks2.waitBestEffort(doc.delete());
  }
}