Fix _is_gcs_s3 to accept access keys of more than 20 chars
authorYoan Tournade <yoan@ytotech.com>
Fri, 28 Dec 2018 00:54:29 +0000 (01:54 +0100)
committerRick van de Loo <rickvandeloo@gmail.com>
Fri, 4 Jan 2019 10:10:47 +0000 (11:10 +0100)
Google Cloud Storage currently emits access keys of more than 20 characters

Signed-off-by: Rick van de Loo <rickvandeloo@gmail.com>
libcloud/common/google.py
libcloud/test/common/test_google.py

index 806e022..9648ee1 100644 (file)
@@ -610,9 +610,12 @@ class GoogleAuthType(object):
     @staticmethod
     def _is_gcs_s3(user_id):
         """
-        Checks S3 key format: 20 alphanumeric chars starting with GOOG.
+        Checks S3 key format: alphanumeric chars starting with GOOG.
         """
-        return len(user_id) == 20 and user_id.startswith('GOOG')
+        return (
+            len(user_id) >= 20 and len(user_id) < 30 and user_id
+            .startswith('GOOG')
+        )
 
     @staticmethod
     def _is_sa(user_id):
index a166910..d01dc42 100644 (file)
@@ -60,7 +60,9 @@ GCE_PARAMS_JSON_KEY = ('email@developer.gserviceaccount.com', JSON_KEY)
 GCE_PARAMS_KEY = ('email@developer.gserviceaccount.com', KEY_STR)
 GCE_PARAMS_IA = ('client_id', 'client_secret')
 GCE_PARAMS_GCE = ('foo', 'bar')
-GCS_S3_PARAMS = ('GOOG0123456789ABCXYZ',  # GOOG + 16 alphanumeric chars
+GCS_S3_PARAMS_20 = ('GOOG0123456789ABCXYZ',  # GOOG + 16 alphanumeric chars
+                 '0102030405060708091011121314151617181920')  # 40 base64 chars
+GCS_S3_PARAMS_24 = ('GOOGDF5OVRRGU4APFNSTVCXI',  # GOOG + 20 alphanumeric chars
                  '0102030405060708091011121314151617181920')  # 40 base64 chars
 
 STUB_UTCNOW = _utcnow()
@@ -230,7 +232,10 @@ class GoogleAuthTypeTest(GoogleTestCase):
             self.assertEqual(GoogleAuthType.guess_type(GCE_PARAMS[0]),
                              GoogleAuthType.SA)
             self.assertEqual(
-                GoogleAuthType.guess_type(GCS_S3_PARAMS[0]),
+                GoogleAuthType.guess_type(GCS_S3_PARAMS_20[0]),
+                GoogleAuthType.GCS_S3)
+            self.assertEqual(
+                GoogleAuthType.guess_type(GCS_S3_PARAMS_24[0]),
                 GoogleAuthType.GCS_S3)
             self.assertEqual(GoogleAuthType.guess_type(GCE_PARAMS_GCE[0]),
                              GoogleAuthType.GCE)