Skip to content

Commit

Permalink
Default constructor for jwks object (#346)
Browse files Browse the repository at this point in the history
* 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 <prince.chrismc@gmail.com>
  • Loading branch information
justend29 and prince-chrismc committed Apr 24, 2024
1 parent 1611f58 commit 461162c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ The minimum is `jwt.h` but you will need to add the defines:
- [`JWT_DISABLE_BASE64`](https://github.com/Thalhammer/jwt-cpp/blob/c9a511f436eaa13857336ebeb44dbc5b7860fe01/include/jwt-cpp/jwt.h#L11)
- [`JWT_DISABLE_PICOJSON`](https://github.com/Thalhammer/jwt-cpp/blob/c9a511f436eaa13857336ebeb44dbc5b7860fe01/include/jwt-cpp/jwt.h#L4)

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

### CMake

Expand Down
5 changes: 5 additions & 0 deletions include/jwt-cpp/jwt.h
Original file line number Diff line number Diff line change
Expand Up @@ -3798,6 +3798,11 @@ namespace jwt {
using iterator = typename jwks_vector_t::iterator;
using const_iterator = typename jwks_vector_t::const_iterator;

/**
* Default constructor producing an empty object without any keys
*/
jwks() = default;

/**
* Parses a string buffer to extract the JWKS.
* \param str buffer containing JSON object representing a JWKS
Expand Down
11 changes: 10 additions & 1 deletion tests/JwksTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ TEST(JwksTest, Missingx5c) {
ASSERT_EQ(jwk3.get_x5c_key_value(), "1");
}

TEST(JwksTest, DefaultConstructor) {
using Jwks = decltype(jwt::parse_jwks(std::declval<std::string>()));

Jwks keys{};
ASSERT_EQ(keys.begin(), keys.end());
ASSERT_FALSE(keys.has_jwk(""));
ASSERT_FALSE(keys.has_jwk("random-jwt"));
}

TEST(JwksTest, CachingBasedOnKid) {
std::string public_key = R"({
"keys": [{
Expand Down Expand Up @@ -149,4 +158,4 @@ TEST(JwksTest, CachingBasedOnKid) {
}

ASSERT_EQ(xs.size(), 2);
}
}

0 comments on commit 461162c

Please sign in to comment.