[ARVADOS] updated: 2.1.0-261-gf37a98d95

Git user git at public.arvados.org
Tue Jan 19 21:47:33 UTC 2021


Summary of changes:
 lib/controller/rpc/conn.go                         | 33 +----------
 .../functional/user_sessions_controller_test.rb    | 68 ++++++++--------------
 2 files changed, 26 insertions(+), 75 deletions(-)

       via  f37a98d9509da449abf0d8c7bca298d0e702f4c9 (commit)
      from  7c3bc0685d120eab7365fc18c06a174427c92312 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit f37a98d9509da449abf0d8c7bca298d0e702f4c9
Author: Nico Cesar <nico at nicocesar.com>
Date:   Tue Jan 19 16:47:00 2021 -0500

    adressing https://dev.arvados.org/issues/17014#note-38
    
    Arvados-DCO-1.1-Signed-off-by: Nico Cesar <nico at curii.com>

diff --git a/lib/controller/rpc/conn.go b/lib/controller/rpc/conn.go
index e9c3bb264..455c20fa9 100644
--- a/lib/controller/rpc/conn.go
+++ b/lib/controller/rpc/conn.go
@@ -127,37 +127,10 @@ func (conn *Conn) requestAndDecode(ctx context.Context, dst interface{}, ep arva
 		if tmp, ok2 := authinfo.(map[string]interface{}); ok2 {
 			for k, v := range tmp {
 				if strings.HasSuffix(k, "_at") {
-					// Format non-nil timestamps as
-					// rfc3339NanoFixed (otherwise they would use
-					// the default time encoding, which omits
-					// trailing zeroes).
-					switch tv := v.(type) {
-					case *time.Time:
-						if tv == nil || tv.IsZero() {
-							tmp[k] = nil
-						} else {
-							tmp[k] = tv.Format(rfc3339NanoFixed)
-						}
-					case time.Time:
-						if tv.IsZero() {
-							tmp[k] = nil
-						} else {
-							tmp[k] = tv.Format(rfc3339NanoFixed)
-						}
-					case string:
-						if tv == "" {
-							tmp[k] = nil
-						} else if strings.HasPrefix(tv, "0001-01-01T00:00:00Z") {
-							tmp[k] = nil
-						} else if t, err := time.Parse(time.RFC3339Nano, tv); err != nil {
-							// pass through an invalid time value (?)
-						} else if t.IsZero() {
-							tmp[k] = nil
-						} else {
-							tmp[k] = t.Format(rfc3339NanoFixed)
-						}
+					// Change zero times values to nil
+					if v, ok3 := v.(string); ok3 && (strings.HasPrefix(v, "0001-01-01T00:00:00") || v == "") {
+						tmp[k] = nil
 					}
-
 				}
 			}
 		}
diff --git a/services/api/test/functional/user_sessions_controller_test.rb b/services/api/test/functional/user_sessions_controller_test.rb
index e3638446c..129464cf1 100644
--- a/services/api/test/functional/user_sessions_controller_test.rb
+++ b/services/api/test/functional/user_sessions_controller_test.rb
@@ -46,52 +46,30 @@ class UserSessionsControllerTest < ActionController::TestCase
                     api_client_auth.updated_at + token_lifetime,
                     1.second)
   end
-  test "login with no configured lifetime and request has expires_at" do
-    token_lifetime = 0
-    Rails.configuration.Login.TokenLifetime = token_lifetime
-    request_expires_at = Time.now + 30.minutes
-    authorize_with :inactive
-    @request.headers['Authorization'] = 'Bearer '+Rails.configuration.SystemRootToken
-    get :create, params: {provider: 'controller', auth_info: {email: "foo at bar.com", expires_at: request_expires_at}, return_to: ',https://app.example'}
-    assert_response :redirect
-    api_client_auth = assigns(:api_client_auth)
-    assert_not_nil api_client_auth
-    assert_not_nil assigns(:api_client)
-    assert_in_delta(api_client_auth.expires_at,
-                    request_expires_at,
-                    1.second)
-  end
 
-  test "login with configured lifetime and request has small expires_at" do
-    token_lifetime = 1.hour
-    Rails.configuration.Login.TokenLifetime = token_lifetime
-    request_expires_at = Time.now + 30.minutes
-    authorize_with :inactive
-    @request.headers['Authorization'] = 'Bearer '+Rails.configuration.SystemRootToken
-    get :create, params: {provider: 'controller', auth_info: {email: "foo at bar.com", expires_at: request_expires_at}, return_to: ',https://app.example'}
-    assert_response :redirect
-    api_client_auth = assigns(:api_client_auth)
-    assert_not_nil api_client_auth
-    assert_not_nil assigns(:api_client)
-    assert_in_delta(api_client_auth.expires_at,
-                    request_expires_at,
-                    1.second)
-  end
-
-  test "login with configured lifetime and request has larger expires_at" do
-    token_lifetime = 1.hour
-    Rails.configuration.Login.TokenLifetime = token_lifetime
-    request_expires_at = Time.now + 90.minutes
-    authorize_with :inactive
-    @request.headers['Authorization'] = 'Bearer '+Rails.configuration.SystemRootToken
-    get :create, params: {provider: 'controller', auth_info: {email: "foo at bar.com", expires_at: request_expires_at}, return_to: ',https://app.example'}
-    assert_response :redirect
-    api_client_auth = assigns(:api_client_auth)
-    assert_not_nil api_client_auth
-    assert_not_nil assigns(:api_client)
-    assert_in_delta(api_client_auth.expires_at,
-                    api_client_auth.updated_at + token_lifetime,
-                    1.second)
+  [[0, 1.hour, 1.hour],
+  [1.hour, 2.hour, 1.hour],
+  [2.hour, 1.hour, 1.hour],
+  [2.hour, nil, 2.hour],
+  ].each do |config_lifetime, request_lifetime, expect_lifetime|
+    test "login with TokenLifetime=#{config_lifetime} and request has expires_at=#{ request_lifetime.nil? ? "nil" : request_lifetime }" do
+      Rails.configuration.Login.TokenLifetime = config_lifetime
+      expected_expiration_time =  Time.now() + expect_lifetime
+      authorize_with :inactive
+      @request.headers['Authorization'] = 'Bearer '+Rails.configuration.SystemRootToken
+      if request_lifetime.nil?
+        get :create, params: {provider: 'controller', auth_info: {email: "foo at bar.com"}, return_to: ',https://app.example'}
+      else
+        get :create, params: {provider: 'controller', auth_info: {email: "foo at bar.com", expires_at: Time.now() + request_lifetime}, return_to: ',https://app.example'}
+      end
+      assert_response :redirect
+      api_client_auth = assigns(:api_client_auth)
+      assert_not_nil api_client_auth
+      assert_not_nil assigns(:api_client)
+      assert_in_delta(api_client_auth.expires_at,
+                      expected_expiration_time,
+                      1.second)
+    end
   end
 
   test "login with remote param returns a salted token" do

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list