Exemplo n.º 1
0
 def test_resolve_auth_with_empty_credstore_and_auth_dict(self):
     auth_config = {
         'auths': auth.parse_auth({
             'https://index.docker.io/v1/': self.index_config,
         }),
         'credsStore': 'blackbox'
     }
     with mock.patch('docker.auth._resolve_authconfig_credstore') as m:
         m.return_value = None
         assert 'indexuser' == auth.resolve_authconfig(
             auth_config, None
         )['username']
Exemplo n.º 2
0
 def test_resolve_auth_with_empty_credstore_and_auth_dict(self):
     auth_config = {
         'auths':
         auth.parse_auth({
             'https://index.docker.io/v1/': self.index_config,
         }),
         'credsStore':
         'blackbox'
     }
     with mock.patch('docker.auth._resolve_authconfig_credstore') as m:
         m.return_value = None
         assert 'indexuser' == auth.resolve_authconfig(auth_config,
                                                       None)['username']
Exemplo n.º 3
0
class ResolveAuthTest(unittest.TestCase):
    index_config = {'auth': encode_auth({'username': '******'})}
    private_config = {'auth': encode_auth({'username': '******'})}
    legacy_config = {'auth': encode_auth({'username': '******'})}

    auth_config = auth.parse_auth({
        'https://index.docker.io/v1/':
        index_config,
        'my.registry.net':
        private_config,
        'http://legacy.registry.url/v1/':
        legacy_config,
    })

    def test_resolve_authconfig_hostname_only(self):
        self.assertEqual(
            auth.resolve_authconfig(self.auth_config,
                                    'my.registry.net')['username'],
            'privateuser')

    def test_resolve_authconfig_no_protocol(self):
        self.assertEqual(
            auth.resolve_authconfig(self.auth_config,
                                    'my.registry.net/v1/')['username'],
            'privateuser')

    def test_resolve_authconfig_no_path(self):
        self.assertEqual(
            auth.resolve_authconfig(self.auth_config,
                                    'http://my.registry.net')['username'],
            'privateuser')

    def test_resolve_authconfig_no_path_trailing_slash(self):
        self.assertEqual(
            auth.resolve_authconfig(self.auth_config,
                                    'http://my.registry.net/')['username'],
            'privateuser')

    def test_resolve_authconfig_no_path_wrong_secure_proto(self):
        self.assertEqual(
            auth.resolve_authconfig(self.auth_config,
                                    'https://my.registry.net')['username'],
            'privateuser')

    def test_resolve_authconfig_no_path_wrong_insecure_proto(self):
        self.assertEqual(
            auth.resolve_authconfig(self.auth_config,
                                    'http://index.docker.io')['username'],
            'indexuser')

    def test_resolve_authconfig_path_wrong_proto(self):
        self.assertEqual(
            auth.resolve_authconfig(self.auth_config,
                                    'https://my.registry.net/v1/')['username'],
            'privateuser')

    def test_resolve_authconfig_default_registry(self):
        self.assertEqual(
            auth.resolve_authconfig(self.auth_config)['username'], 'indexuser')

    def test_resolve_authconfig_default_explicit_none(self):
        self.assertEqual(
            auth.resolve_authconfig(self.auth_config, None)['username'],
            'indexuser')

    def test_resolve_authconfig_fully_explicit(self):
        self.assertEqual(
            auth.resolve_authconfig(self.auth_config,
                                    'http://my.registry.net/v1/')['username'],
            'privateuser')

    def test_resolve_authconfig_legacy_config(self):
        self.assertEqual(
            auth.resolve_authconfig(self.auth_config,
                                    'legacy.registry.url')['username'],
            'legacyauth')

    def test_resolve_authconfig_no_match(self):
        self.assertTrue(
            auth.resolve_authconfig(self.auth_config, 'does.not.exist') is None
        )

    def test_resolve_registry_and_auth_library_image(self):
        image = 'image'
        self.assertEqual(
            auth.resolve_authconfig(
                self.auth_config,
                auth.resolve_repository_name(image)[0])['username'],
            'indexuser',
        )

    def test_resolve_registry_and_auth_hub_image(self):
        image = 'username/image'
        self.assertEqual(
            auth.resolve_authconfig(
                self.auth_config,
                auth.resolve_repository_name(image)[0])['username'],
            'indexuser',
        )

    def test_resolve_registry_and_auth_explicit_hub(self):
        image = 'docker.io/username/image'
        self.assertEqual(
            auth.resolve_authconfig(
                self.auth_config,
                auth.resolve_repository_name(image)[0])['username'],
            'indexuser',
        )

    def test_resolve_registry_and_auth_explicit_legacy_hub(self):
        image = 'index.docker.io/username/image'
        self.assertEqual(
            auth.resolve_authconfig(
                self.auth_config,
                auth.resolve_repository_name(image)[0])['username'],
            'indexuser',
        )

    def test_resolve_registry_and_auth_private_registry(self):
        image = 'my.registry.net/image'
        self.assertEqual(
            auth.resolve_authconfig(
                self.auth_config,
                auth.resolve_repository_name(image)[0])['username'],
            'privateuser',
        )

    def test_resolve_registry_and_auth_unauthenticated_registry(self):
        image = 'other.registry.net/image'
        self.assertEqual(
            auth.resolve_authconfig(self.auth_config,
                                    auth.resolve_repository_name(image)[0]),
            None,
        )
Exemplo n.º 4
0
class ResolveAuthTest(unittest.TestCase):
    index_config = {'auth': encode_auth({'username': '******'})}
    private_config = {'auth': encode_auth({'username': '******'})}
    legacy_config = {'auth': encode_auth({'username': '******'})}

    auth_config = {
        'auths':
        auth.parse_auth({
            'https://index.docker.io/v1/': index_config,
            'my.registry.net': private_config,
            'http://legacy.registry.url/v1/': legacy_config,
        })
    }

    def test_resolve_authconfig_hostname_only(self):
        assert auth.resolve_authconfig(
            self.auth_config, 'my.registry.net')['username'] == 'privateuser'

    def test_resolve_authconfig_no_protocol(self):
        assert auth.resolve_authconfig(
            self.auth_config,
            'my.registry.net/v1/')['username'] == 'privateuser'

    def test_resolve_authconfig_no_path(self):
        assert auth.resolve_authconfig(
            self.auth_config,
            'http://my.registry.net')['username'] == 'privateuser'

    def test_resolve_authconfig_no_path_trailing_slash(self):
        assert auth.resolve_authconfig(
            self.auth_config,
            'http://my.registry.net/')['username'] == 'privateuser'

    def test_resolve_authconfig_no_path_wrong_secure_proto(self):
        assert auth.resolve_authconfig(
            self.auth_config,
            'https://my.registry.net')['username'] == 'privateuser'

    def test_resolve_authconfig_no_path_wrong_insecure_proto(self):
        assert auth.resolve_authconfig(
            self.auth_config,
            'http://index.docker.io')['username'] == 'indexuser'

    def test_resolve_authconfig_path_wrong_proto(self):
        assert auth.resolve_authconfig(
            self.auth_config,
            'https://my.registry.net/v1/')['username'] == 'privateuser'

    def test_resolve_authconfig_default_registry(self):
        assert auth.resolve_authconfig(
            self.auth_config)['username'] == 'indexuser'

    def test_resolve_authconfig_default_explicit_none(self):
        assert auth.resolve_authconfig(self.auth_config,
                                       None)['username'] == 'indexuser'

    def test_resolve_authconfig_fully_explicit(self):
        assert auth.resolve_authconfig(
            self.auth_config,
            'http://my.registry.net/v1/')['username'] == 'privateuser'

    def test_resolve_authconfig_legacy_config(self):
        assert auth.resolve_authconfig(
            self.auth_config,
            'legacy.registry.url')['username'] == 'legacyauth'

    def test_resolve_authconfig_no_match(self):
        assert auth.resolve_authconfig(self.auth_config,
                                       'does.not.exist') is None

    def test_resolve_registry_and_auth_library_image(self):
        image = 'image'
        assert auth.resolve_authconfig(
            self.auth_config,
            auth.resolve_repository_name(image)[0])['username'] == 'indexuser'

    def test_resolve_registry_and_auth_hub_image(self):
        image = 'username/image'
        assert auth.resolve_authconfig(
            self.auth_config,
            auth.resolve_repository_name(image)[0])['username'] == 'indexuser'

    def test_resolve_registry_and_auth_explicit_hub(self):
        image = 'docker.io/username/image'
        assert auth.resolve_authconfig(
            self.auth_config,
            auth.resolve_repository_name(image)[0])['username'] == 'indexuser'

    def test_resolve_registry_and_auth_explicit_legacy_hub(self):
        image = 'index.docker.io/username/image'
        assert auth.resolve_authconfig(
            self.auth_config,
            auth.resolve_repository_name(image)[0])['username'] == 'indexuser'

    def test_resolve_registry_and_auth_private_registry(self):
        image = 'my.registry.net/image'
        assert auth.resolve_authconfig(self.auth_config,
                                       auth.resolve_repository_name(image)
                                       [0])['username'] == 'privateuser'

    def test_resolve_registry_and_auth_unauthenticated_registry(self):
        image = 'other.registry.net/image'
        assert auth.resolve_authconfig(
            self.auth_config,
            auth.resolve_repository_name(image)[0]) is None

    def test_resolve_auth_with_empty_credstore_and_auth_dict(self):
        auth_config = {
            'auths':
            auth.parse_auth({
                'https://index.docker.io/v1/': self.index_config,
            }),
            'credsStore':
            'blackbox'
        }
        with mock.patch('docker.auth._resolve_authconfig_credstore') as m:
            m.return_value = None
            assert 'indexuser' == auth.resolve_authconfig(auth_config,
                                                          None)['username']