Пример #1
0
    def setUp(self):
        self.domain = 'domain'
        self.domain_owner = 'domain-owner'
        self.package_format = 'npm'
        self.repository = 'repository'
        self.auth_token = 'auth-token'
        self.endpoint = 'https://{domain}-{domainOwner}.codeartifact.aws.' \
            'a2z.com/{format}/{repository}/'.format(
                domain=self.domain,
                domainOwner=self.domain_owner,
                format=self.package_format,
                repository=self.repository
            )

        repo_uri = urlparse.urlsplit(self.endpoint)
        always_auth_config = '//{}{}:always-auth'.format(
            repo_uri.netloc, repo_uri.path)
        auth_token_config = '//{}{}:_authToken'.format(repo_uri.netloc,
                                                       repo_uri.path)
        self.commands = []
        self.commands.append(
            [self.NPM_CMD, 'config', 'set', 'registry', self.endpoint])
        self.commands.append(
            [self.NPM_CMD, 'config', 'set', always_auth_config, 'true'])
        self.commands.append([
            self.NPM_CMD, 'config', 'set', auth_token_config, self.auth_token
        ])

        self.subprocess_utils = mock.Mock()

        self.test_subject = NpmLogin(self.auth_token, self.endpoint,
                                     self.subprocess_utils)
Пример #2
0
    def setUp(self):
        self.domain = 'domain'
        self.domain_owner = 'domain-owner'
        self.package_format = 'npm'
        self.repository = 'repository'
        self.auth_token = 'auth-token'
        self.namespace = 'namespace'
        self.expiration = (datetime.now(tzlocal()) + relativedelta(hours=10) +
                           relativedelta(minutes=9)).replace(microsecond=0)
        self.endpoint = 'https://{domain}-{domainOwner}.codeartifact.aws.' \
            'a2z.com/{format}/{repository}/'.format(
                domain=self.domain,
                domainOwner=self.domain_owner,
                format=self.package_format,
                repository=self.repository
            )

        repo_uri = urlparse.urlsplit(self.endpoint)
        always_auth_config = '//{}{}:always-auth'.format(
            repo_uri.netloc, repo_uri.path)
        auth_token_config = '//{}{}:_authToken'.format(repo_uri.netloc,
                                                       repo_uri.path)
        self.commands = []
        self.commands.append(
            [self.NPM_CMD, 'config', 'set', 'registry', self.endpoint])
        self.commands.append(
            [self.NPM_CMD, 'config', 'set', always_auth_config, 'true'])
        self.commands.append([
            self.NPM_CMD, 'config', 'set', auth_token_config, self.auth_token
        ])

        self.subprocess_utils = mock.Mock()

        self.test_subject = NpmLogin(self.auth_token, self.expiration,
                                     self.endpoint, self.subprocess_utils)
Пример #3
0
class TestNpmLogin(unittest.TestCase):

    NPM_CMD = NpmLogin.NPM_CMD

    def setUp(self):
        self.domain = 'domain'
        self.domain_owner = 'domain-owner'
        self.package_format = 'npm'
        self.repository = 'repository'
        self.auth_token = 'auth-token'
        self.expiration = (datetime.now(tzlocal()) + relativedelta(hours=10) +
                           relativedelta(minutes=9)).replace(microsecond=0)
        self.endpoint = 'https://{domain}-{domainOwner}.codeartifact.aws.' \
            'a2z.com/{format}/{repository}/'.format(
                domain=self.domain,
                domainOwner=self.domain_owner,
                format=self.package_format,
                repository=self.repository
            )

        repo_uri = urlparse.urlsplit(self.endpoint)
        always_auth_config = '//{}{}:always-auth'.format(
            repo_uri.netloc, repo_uri.path)
        auth_token_config = '//{}{}:_authToken'.format(repo_uri.netloc,
                                                       repo_uri.path)
        self.commands = []
        self.commands.append(
            [self.NPM_CMD, 'config', 'set', 'registry', self.endpoint])
        self.commands.append(
            [self.NPM_CMD, 'config', 'set', always_auth_config, 'true'])
        self.commands.append([
            self.NPM_CMD, 'config', 'set', auth_token_config, self.auth_token
        ])

        self.subprocess_utils = mock.Mock()

        self.test_subject = NpmLogin(self.auth_token, self.expiration,
                                     self.endpoint, self.subprocess_utils)

    def test_login(self):
        self.test_subject.login()
        expected_calls = [
            mock.call(
                command,
                stdout=self.subprocess_utils.PIPE,
                stderr=self.subprocess_utils.PIPE,
            ) for command in self.commands
        ]
        self.subprocess_utils.check_call.assert_has_calls(expected_calls,
                                                          any_order=True)

    def test_get_commands(self):
        commands = self.test_subject.get_commands(self.endpoint,
                                                  self.auth_token)
        self.assertCountEqual(commands, self.commands)

    def test_login_dry_run(self):
        self.test_subject.login(dry_run=True)
        self.subprocess_utils.check_call.assert_not_called()