From ac292054429be582b1aecfb2bc8a4adc97c6b77f Mon Sep 17 00:00:00 2001 From: Wehrli Date: Wed, 11 Jul 2018 14:34:30 +0200 Subject: [PATCH] Fixes RegistryAuthenticator to handle case insensitive Basic method (#539) (#546) --- .../tools/jib/registry/RegistryAuthenticator.java | 5 +++-- .../tools/jib/registry/RegistryAuthenticatorTest.java | 10 ++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/jib-core/src/main/java/com/google/cloud/tools/jib/registry/RegistryAuthenticator.java b/jib-core/src/main/java/com/google/cloud/tools/jib/registry/RegistryAuthenticator.java index f64935de91..bb057fcb64 100644 --- a/jib-core/src/main/java/com/google/cloud/tools/jib/registry/RegistryAuthenticator.java +++ b/jib-core/src/main/java/com/google/cloud/tools/jib/registry/RegistryAuthenticator.java @@ -55,8 +55,9 @@ public class RegistryAuthenticator { @Nullable static RegistryAuthenticator fromAuthenticationMethod( String authenticationMethod, String repository) throws RegistryAuthenticationFailedException { - // If the authentication method starts with 'Basic ', no registry authentication is needed. - if (authenticationMethod.matches("^Basic .*")) { + // If the authentication method starts with 'basic ' (case insensitive), no registry + // authentication is needed. + if (authenticationMethod.matches("^(?i)(basic) .*")) { return null; } diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/registry/RegistryAuthenticatorTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/registry/RegistryAuthenticatorTest.java index 0d661afc3b..9fda0ddfb1 100644 --- a/jib-core/src/test/java/com/google/cloud/tools/jib/registry/RegistryAuthenticatorTest.java +++ b/jib-core/src/test/java/com/google/cloud/tools/jib/registry/RegistryAuthenticatorTest.java @@ -42,6 +42,16 @@ public void testFromAuthenticationMethod_basic() throws RegistryAuthenticationFa RegistryAuthenticator.fromAuthenticationMethod( "Basic realm=\"https://somerealm\",service=\"someservice\",scope=\"somescope\"", "someimage")); + + Assert.assertNull( + RegistryAuthenticator.fromAuthenticationMethod( + "BASIC realm=\"https://somerealm\",service=\"someservice\",scope=\"somescope\"", + "someimage")); + + Assert.assertNull( + RegistryAuthenticator.fromAuthenticationMethod( + "bASIC realm=\"https://somerealm\",service=\"someservice\",scope=\"somescope\"", + "someimage")); } @Test