-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #725 from jfbenckhuijsen/feature/firebase-auth-roles
Feature/firebase auth roles
- Loading branch information
Showing
7 changed files
with
139 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,15 +8,24 @@ | |
import static org.hamcrest.Matchers.not; | ||
|
||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import com.google.firebase.auth.FirebaseAuth; | ||
import com.google.firebase.auth.FirebaseAuthException; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.restassured.http.ContentType; | ||
|
||
@QuarkusTest | ||
class FirebaseAuthResourceTest extends FirebaseAuthTest { | ||
|
||
@Inject | ||
FirebaseAuth firebaseAuth; | ||
|
||
@Test | ||
void shouldCreateUser() { | ||
given() | ||
|
@@ -62,4 +71,51 @@ void shouldStoreCustomUserClaims() { | |
.body("customClaims", hasEntry("role", "admin")); | ||
} | ||
|
||
@Test | ||
void shouldHandleRoles() throws FirebaseAuthException { | ||
given() | ||
.contentType(ContentType.JSON) | ||
.queryParam("uid", "6789") | ||
.queryParam("email", "[email protected]") | ||
.queryParam("displayName", "John Doe") | ||
.post("/auth/users/create") | ||
.then() | ||
.log().ifValidationFails() | ||
.statusCode(200) | ||
.body("uid", equalTo("6789")) | ||
.body("customClaims", anEmptyMap()); | ||
|
||
given() | ||
.contentType(ContentType.JSON) | ||
.body(Map.of("roles", Set.of("admin"))) | ||
.put("/auth/users/{uid}/claims", 6789) | ||
.then() | ||
.log().ifValidationFails() | ||
.statusCode(204); | ||
|
||
var customToken = firebaseAuth.createCustomToken("6789"); | ||
|
||
var emulatorHostParts = emulatorHost.split(":"); | ||
var port = emulatorHostParts.length == 2 ? Integer.parseInt(emulatorHostParts[1]) : 9099; | ||
|
||
var bodyAsJson = given() | ||
.urlEncodingEnabled(false) | ||
.port(port) | ||
.contentType(ContentType.JSON) | ||
.body(Map.of("token", customToken, "returnSecureToken", true)) | ||
.log().all() | ||
.post("identitytoolkit.googleapis.com/v1/accounts:signInWithCustomToken?key=test") | ||
.jsonPath(); | ||
var idToken = bodyAsJson.get("idToken"); | ||
|
||
given() | ||
.header("Authorization", "Bearer " + idToken) | ||
.get("/app/admin-options") | ||
.then() | ||
.log().ifValidationFails() | ||
.statusCode(200) | ||
.body("projectId", equalTo("demo-test-project-id")); | ||
|
||
} | ||
|
||
} |