@@ -167,6 +167,11 @@ class SerializeTest : public ::testing::Test {
167167 " 1" , ec_public, &err_msg);
168168 ASSERT_TRUE (rv == 0 );
169169
170+ scitoken_set_lifetime (m_token.get (), 60 );
171+
172+ m_audiences_array.push_back (" https://demo.scitokens.org/" );
173+ m_audiences_array.push_back (nullptr );
174+
170175 const char *groups[3 ] = {nullptr , nullptr , nullptr };
171176 const char group0[] = " group0" ;
172177 const char group1[] = " group1" ;
@@ -186,6 +191,8 @@ class SerializeTest : public ::testing::Test {
186191 using TokenPtr = std::unique_ptr<void , decltype (&scitoken_destroy)>;
187192 TokenPtr m_token{nullptr , scitoken_destroy};
188193
194+ std::vector<const char *> m_audiences_array;
195+
189196 TokenPtr m_read_token{nullptr , scitoken_destroy};
190197};
191198
@@ -354,11 +361,7 @@ TEST_F(SerializeTest, EnforcerTest) {
354361 " https://demo.scitokens.org/" , &err_msg);
355362 ASSERT_TRUE (rv == 0 );
356363
357- std::vector<const char *> audiences_array;
358- audiences_array.push_back (" https://demo.scitokens.org/" );
359- audiences_array.push_back (nullptr );
360-
361- auto enforcer = enforcer_create (" https://demo.scitokens.org/gtest" , &audiences_array[0 ], &err_msg);
364+ auto enforcer = enforcer_create (" https://demo.scitokens.org/gtest" , &m_audiences_array[0 ], &err_msg);
362365 ASSERT_TRUE (enforcer != nullptr );
363366
364367 Acl acl;
@@ -394,11 +397,7 @@ TEST_F(SerializeTest, EnforcerScopeTest) {
394397 " https://demo.scitokens.org/" , &err_msg);
395398 ASSERT_TRUE (rv == 0 );
396399
397- std::vector<const char *> audiences_array;
398- audiences_array.push_back (" https://demo.scitokens.org/" );
399- audiences_array.push_back (nullptr );
400-
401- auto enforcer = enforcer_create (" https://demo.scitokens.org/gtest" , &audiences_array[0 ], &err_msg);
400+ auto enforcer = enforcer_create (" https://demo.scitokens.org/gtest" , &m_audiences_array[0 ], &err_msg);
402401 ASSERT_TRUE (enforcer != nullptr );
403402
404403 scitoken_set_serialize_profile (m_token.get (), SciTokenProfile::WLCG_1_0);
@@ -433,10 +432,46 @@ TEST_F(SerializeTest, EnforcerScopeTest) {
433432 }
434433 ASSERT_TRUE (found_read);
435434 ASSERT_TRUE (found_write);
435+ }
436+
437+ TEST_F (SerializeTest, ExplicitTime) {
438+ time_t now = time (NULL );
439+ char *err_msg;
440+
441+ scitoken_set_serialize_profile (m_token.get (), SciTokenProfile::WLCG_1_0);
442+ auto rv = scitoken_set_claim_string (m_token.get (), " scope" ,
443+ " storage.read:/" , &err_msg);
444+
445+ char *token_value = nullptr ;
446+ rv = scitoken_serialize (m_token.get (), &token_value, &err_msg);
447+ ASSERT_TRUE (rv == 0 );
436448
449+ rv = scitoken_deserialize_v2 (token_value, m_read_token.get (), nullptr , &err_msg);
450+ ASSERT_TRUE (rv == 0 );
437451
452+ auto enforcer = enforcer_create (" https://demo.scitokens.org/gtest" , &m_audiences_array[0 ], &err_msg);
453+ ASSERT_TRUE (enforcer != nullptr );
454+ Acl *acls;
455+ rv = enforcer_generate_acls (enforcer, m_read_token.get (), &acls, &err_msg);
456+ if (rv) {
457+ printf (" Failure when generating ACLs: %s\n " , err_msg);
458+ }
459+ ASSERT_TRUE (rv == 0 );
460+ ASSERT_TRUE (acls != nullptr );
461+
462+ enforcer_set_time (enforcer, time (NULL ), &err_msg);
463+ rv = enforcer_generate_acls (enforcer, m_read_token.get (), &acls, &err_msg);
464+ ASSERT_TRUE (rv == 0 );
438465
466+ enforcer_set_time (enforcer, time (NULL ) + 100 , &err_msg);
467+ rv = enforcer_generate_acls (enforcer, m_read_token.get (), &acls, &err_msg);
468+ ASSERT_FALSE (rv == 0 );
469+
470+ enforcer_set_time (enforcer, time (NULL ) - 100 , &err_msg);
471+ rv = enforcer_generate_acls (enforcer, m_read_token.get (), &acls, &err_msg);
472+ ASSERT_FALSE (rv == 0 );
439473
474+ enforcer_destroy (enforcer);
440475}
441476
442477}
0 commit comments