From e6ef9eaf9ea30690a8f7108ed21b7b9e18260aef Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Fri, 28 May 2021 16:40:49 -0400 Subject: [PATCH] 17722: Tweak tests to be clearer about new behavior Arvados-DCO-1.1-Signed-off-by: Peter Amstutz --- .../integration/api_client_authorizations_api_test.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/services/api/test/integration/api_client_authorizations_api_test.rb b/services/api/test/integration/api_client_authorizations_api_test.rb index a366664e0d..405e4bf687 100644 --- a/services/api/test/integration/api_client_authorizations_api_test.rb +++ b/services/api/test/integration/api_client_authorizations_api_test.rb @@ -124,7 +124,7 @@ class ApiClientAuthorizationsApiTest < ActionDispatch::IntegrationTest end end - test "expires_at can be set to #{desired_expiration.nil? ? 'nil' : 'exceed the limit'} by admins when API.MaxTokenLifetime is set" do + test "behavior when expires_at is set to #{desired_expiration.nil? ? 'nil' : 'exceed the limit'} by admins when API.MaxTokenLifetime is set" do Rails.configuration.API.MaxTokenLifetime = 1.hour # Test token creation @@ -139,15 +139,15 @@ class ApiClientAuthorizationsApiTest < ActionDispatch::IntegrationTest headers: {'HTTP_AUTHORIZATION' => "OAuth2 #{api_client_authorizations(:admin_trustedclient).api_token}"} assert_response 200 if desired_expiration.nil? - assert_equal json_response['expires_at'].to_time.to_i, (db_current_time + Rails.configuration.API.MaxTokenLifetime).to_i + # When expires_at is nil, default to MaxTokenLifetime + assert_operator (json_response['expires_at'].to_time.to_i - (db_current_time + Rails.configuration.API.MaxTokenLifetime).to_i).abs, :<, 2 else assert_equal json_response['expires_at'].to_time.to_i, desired_expiration.to_i end # Test token update (reverse the above behavior) - previous_expiration = json_response['expires_at'] token_uuid = json_response['uuid'] - if previous_expiration.nil? + if desired_expiration.nil? submitted_updated_expiration = db_current_time + Rails.configuration.API.MaxTokenLifetime + 1.hour else submitted_updated_expiration = nil @@ -161,7 +161,7 @@ class ApiClientAuthorizationsApiTest < ActionDispatch::IntegrationTest headers: {'HTTP_AUTHORIZATION' => "OAuth2 #{api_client_authorizations(:admin_trustedclient).api_token}"} assert_response 200 if submitted_updated_expiration.nil? - assert_equal json_response['expires_at'].to_time.to_i, (db_current_time + Rails.configuration.API.MaxTokenLifetime).to_i + assert_operator (json_response['expires_at'].to_time.to_i - (db_current_time + Rails.configuration.API.MaxTokenLifetime).to_i).abs, :<, 2 else assert_equal json_response['expires_at'].to_time.to_i, submitted_updated_expiration.to_i end -- 2.30.2