-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add client assertion restrictions, and code tidy up (#423)
* Add jwt client assertion restrictions and tests * Replace `system_clock` with `steady_clock` when calculating the response time * Tidy up
- Loading branch information
Showing
5 changed files
with
91 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// The first "test" is of course whether the header compiles standalone | ||
#include "nmos/jwt_generator.h" | ||
|
||
#include "bst/test/test.h" | ||
#include "cpprest/basic_utils.h" | ||
#include "nmos/jwk_utils.h" // for nmos::experimental::jwk_exception | ||
|
||
namespace | ||
{ | ||
// this is the private key (rsa.api.testsuite.nmos.tv.key.pem) from the nmos-testing | ||
// https://https://github.com/AMWA-TV/nmos-testing/blob/master/test_data/BCP00301/ca/intermediate/private/rsa.api.testsuite.nmos.tv.key.pem | ||
const auto test_private_key = utility::s2us(R"(-----BEGIN RSA PRIVATE KEY----- | ||
MIIEogIBAAKCAQEAyXHgphlqcINx+ZKkBefDo5X5rHUuTpom9OcRKpWQHt7oYUr1 | ||
UhoKJ+8SxbsSvtlrvvGa6kiSk/m6i7haU9dGKSDJzndYJSi+Qbc2jfSPfoHtHvs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qQwm1rOfh4gYHfqK8YsHepbZvGxg | ||
3WDFueXxRteO0355BxEEUO15TyCWxmsq8eFNeKPjvrGzP3EL0eue4etQIQJhYCTT | ||
kREaexqyZ5XqTvQbFFacjQKBgEhC1KKda12/ovtZWTIWokL+rpvryskzH6cDmLKf | ||
mcUsOSZGgu0iiksV8hAjwRby/K9f6H1JpirwDoL9zp8bL3Fi8gjxvMQbRPoY9/O4 | ||
au7dMyvlEDf/je/Gqss/IchboZx+lYCALoYzTmbKu78nJ/bMz2/uTkWMuQCiYYUL | ||
AoEpAoGAYIG2aCsuLV+1bPHC0vYvDC0V+NMA8e9HrplHdrQ4IBxyZnmHqvrGZ+04 | ||
huUpDxAX+hxYap0k0RPJ3HaFmIHz7DpStX/aIjcfucEnoev7OLj4/3j6s2tHfeWL | ||
JP+1+v/YSIKc7WXvz95YsmoJZ02Ikv8zBan9HIzczmkqDe0C1RQ= | ||
-----END RSA PRIVATE KEY----- | ||
)"); | ||
|
||
} | ||
|
||
BST_TEST_CASE(testClientAssertion) | ||
{ | ||
using namespace nmos::experimental; | ||
|
||
const utility::string_t issuer{ U("api.testsuite.nmos.tv") }; | ||
const utility::string_t subject{ U("api.testsuite.nmos.tv") }; | ||
const web::uri audience{ U("https://mocks.testsuite.nmos.tv:5010/testtoken") }; | ||
const std::chrono::seconds token_lifetime{ 100 }; | ||
const utility::string_t private_key{ test_private_key }; | ||
const utility::string_t keyid{ U("key_1") }; | ||
|
||
// bad cases | ||
const utility::string_t bad_issuer{}; | ||
BST_REQUIRE_THROW(jwt_generator::create_client_assertion(bad_issuer, subject, audience, token_lifetime, private_key, keyid), nmos::experimental::jwk_exception); | ||
|
||
const utility::string_t bad_subject{}; | ||
BST_REQUIRE_THROW(jwt_generator::create_client_assertion(issuer, bad_subject, audience, token_lifetime, private_key, keyid), nmos::experimental::jwk_exception); | ||
|
||
const utility::string_t bad_audience{}; | ||
BST_REQUIRE_THROW(jwt_generator::create_client_assertion(issuer, subject, bad_audience, token_lifetime, private_key, keyid), nmos::experimental::jwk_exception); | ||
|
||
const utility::string_t bad_private_key{}; | ||
BST_REQUIRE_THROW(jwt_generator::create_client_assertion(issuer, subject, audience, token_lifetime, bad_private_key, keyid), nmos::experimental::jwk_exception); | ||
|
||
// good case | ||
BST_REQUIRE_NO_THROW(jwt_generator::create_client_assertion(issuer, subject, audience, token_lifetime, private_key, keyid)); | ||
} |