forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract the subject field of a JWT (envoyproxy#967)
Automatic merge from submit-queue. Extract the subject field of a JWT Extract the subject field (i.e., sub) of a JWT, which is used during the authentication. To run the tests: bazel test //src/envoy/auth:jwt_test **What this PR does / why we need it**: Extract the subject field (i.e., sub) of a JWT, which is used during the authentication. **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes envoyproxy#966 **Special notes for your reviewer**: **Release note**: ```release-note ```
- Loading branch information
Showing
3 changed files
with
23 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,7 @@ class DatasetPem { | |
"N09hdvlCtAF87Fu1qqfwEQ93A-J7m08bZJoyIPcNmTcYGHwfMR4-lcI5cC_93C_" | ||
"5BGE1FHPLOHpNghLuM6-rhOtgwZc9ywupn_bBK3QzuAoDnYwpqQhgQL_CdUD_bSHcmWFkw"; | ||
|
||
const std::string kJwtSub = "[email protected]"; | ||
const std::string kJwtHeaderEncoded = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9"; | ||
const std::string kJwtPayloadEncoded = | ||
"eyJpc3MiOiJodHRwczovL2V4YW1wbGUuY29tIiwic3ViIjoidGVzdEBleGFtcGxlLmNvbSIs" | ||
|
@@ -340,7 +341,7 @@ namespace { | |
bool EqJson(Json::ObjectSharedPtr p1, Json::ObjectSharedPtr p2) { | ||
return p1->asJsonString() == p2->asJsonString(); | ||
} | ||
} | ||
} // namespace | ||
|
||
class JwtTest : public testing::Test { | ||
protected: | ||
|
@@ -459,6 +460,17 @@ TEST_F(JwtTestPem, InvalidAlg) { | |
Status::ALG_NOT_IMPLEMENTED, nullptr); | ||
} | ||
|
||
TEST(JwtSubExtractionTest, NonEmptyJwtSubShouldEqual) { | ||
DatasetPem ds; | ||
Jwt jwt(ds.kJwt); | ||
EXPECT_EQ(jwt.Sub(), ds.kJwtSub); | ||
} | ||
|
||
TEST(JwtSubExtractionTest, EmptyJwtSubShouldEqual) { | ||
Jwt jwt(""); | ||
EXPECT_EQ(jwt.Sub(), ""); | ||
} | ||
|
||
// Test cases w/ JWKs-formatted public key | ||
|
||
class JwtTestJwks : public JwtTest { | ||
|