Skip to content

Commit 461162c

Browse files
Default constructor for jwks object (#346)
* correct invalid link to traits.md * default constructor for jwks * Update comment of default constructor * apply automatically generated patch from CI. Damn, that's cool * test JWKs default c'tor using deduced jwt::jwk from available traits * rm unused type_traits from test * apply auto format to jwkstest --------- Co-authored-by: Chris Mc <[email protected]>
1 parent 1611f58 commit 461162c

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

docs/install.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ The minimum is `jwt.h` but you will need to add the defines:
3131
- [`JWT_DISABLE_BASE64`](https://github.com/Thalhammer/jwt-cpp/blob/c9a511f436eaa13857336ebeb44dbc5b7860fe01/include/jwt-cpp/jwt.h#L11)
3232
- [`JWT_DISABLE_PICOJSON`](https://github.com/Thalhammer/jwt-cpp/blob/c9a511f436eaa13857336ebeb44dbc5b7860fe01/include/jwt-cpp/jwt.h#L4)
3333

34-
In addition to providing your own JSON traits implementation, see [traits.md](traits.ms) for more information.
34+
In addition to providing your own JSON traits implementation, see [traits.md](traits.md) for more information.
3535

3636
### CMake
3737

include/jwt-cpp/jwt.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3798,6 +3798,11 @@ namespace jwt {
37983798
using iterator = typename jwks_vector_t::iterator;
37993799
using const_iterator = typename jwks_vector_t::const_iterator;
38003800

3801+
/**
3802+
* Default constructor producing an empty object without any keys
3803+
*/
3804+
jwks() = default;
3805+
38013806
/**
38023807
* Parses a string buffer to extract the JWKS.
38033808
* \param str buffer containing JSON object representing a JWKS

tests/JwksTest.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,15 @@ TEST(JwksTest, Missingx5c) {
117117
ASSERT_EQ(jwk3.get_x5c_key_value(), "1");
118118
}
119119

120+
TEST(JwksTest, DefaultConstructor) {
121+
using Jwks = decltype(jwt::parse_jwks(std::declval<std::string>()));
122+
123+
Jwks keys{};
124+
ASSERT_EQ(keys.begin(), keys.end());
125+
ASSERT_FALSE(keys.has_jwk(""));
126+
ASSERT_FALSE(keys.has_jwk("random-jwt"));
127+
}
128+
120129
TEST(JwksTest, CachingBasedOnKid) {
121130
std::string public_key = R"({
122131
"keys": [{
@@ -149,4 +158,4 @@ TEST(JwksTest, CachingBasedOnKid) {
149158
}
150159

151160
ASSERT_EQ(xs.size(), 2);
152-
}
161+
}

0 commit comments

Comments
 (0)