Skip to content

Commit a449457

Browse files
authored
Merge pull request #94 from djw8605/err_msg_fix
Fixing returning err_msg with enforcer fail
2 parents 910a9bb + 58d1eb9 commit a449457

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

src/scitokens_internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ class Enforcer {
554554
m_validator.verify(scitoken);
555555
return true;
556556
} catch (std::runtime_error &) {
557-
return false;
557+
throw;
558558
}
559559
}
560560

test/main.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,49 @@ TEST_F(SerializeTest, FailVerifyATJWTTest) {
254254
ASSERT_FALSE(rv == 0);
255255
}
256256

257+
TEST_F(SerializeTest, EnforcerTest) {
258+
/*
259+
* Test that the enforcer works and returns an err_msg
260+
*/
261+
char *err_msg = nullptr;
262+
263+
auto rv = scitoken_set_claim_string(m_token.get(), "aud",
264+
"https://demo.scitokens.org/", &err_msg);
265+
ASSERT_TRUE(rv == 0);
266+
267+
std::vector<const char *> audiences_array;
268+
audiences_array.push_back("https://demo.scitokens.org/");
269+
audiences_array.push_back(nullptr);
270+
271+
auto enforcer = enforcer_create("https://demo.scitokens.org/gtest", &audiences_array[0], &err_msg);
272+
ASSERT_TRUE(enforcer != nullptr);
273+
274+
Acl acl;
275+
acl.authz = "read";
276+
acl.resource = "/stuff";
277+
278+
rv = scitoken_set_claim_string(m_token.get(), "scope",
279+
"read:/blah", &err_msg);
280+
ASSERT_TRUE(rv == 0);
281+
282+
rv = scitoken_set_claim_string(m_token.get(), "ver",
283+
"scitoken:2.0", &err_msg);
284+
ASSERT_TRUE(rv == 0);
285+
286+
char *token_value = nullptr;
287+
rv = scitoken_serialize(m_token.get(), &token_value, &err_msg);
288+
ASSERT_TRUE(rv == 0);
289+
std::unique_ptr<char, decltype(&free)> token_value_ptr(token_value, free);
290+
291+
rv = scitoken_deserialize_v2(token_value, m_read_token.get(), nullptr, &err_msg);
292+
ASSERT_TRUE(rv == 0);
293+
294+
rv = enforcer_test(enforcer, m_read_token.get(), &acl, &err_msg);
295+
ASSERT_STREQ(err_msg, "token verification failed: 'scope' claim verification failed.");
296+
ASSERT_TRUE(rv == -1) << err_msg;
297+
298+
}
299+
257300
}
258301

259302
int main(int argc, char **argv) {

0 commit comments

Comments
 (0)