Skip to content

Commit

Permalink
Add TokenAuth tests (again)
Browse files Browse the repository at this point in the history
Now that we have robotello.yaml support added, I went back and redid these tests.

See SatelliteQE#6334 for the previous attempt

- test registries with long passwords (>255)
- start to be able test against a larger number of registries
  • Loading branch information
pgagne authored and JacobCallahan committed Jan 14, 2020
1 parent 9b24366 commit 8362c64
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

# Varies per-deployment.
/robottelo.properties
/robottelo.yaml

# Files generated by Sphinx.
/docs/_build/
Expand Down
24 changes: 24 additions & 0 deletions robotello.yaml.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---

# Container registry and repo set information to use for container repo syncing.
container_repo:
multi_registry_test_configs:
- label: registry1
registry_url: https://registry2.example.com
registry_username: # Username
registry_password: #Token or password
repos_to_sync: [repo1, repo1/x1, repo2/x4] # These really can be anything, just keep them small
- label: registry2
registry_url: https://registry3.example.com
registry_username: #Username
registry_password: #Password or token
repos_to_sync: [repo2, repo3/x1, repo2/x4] # These really can be anything, just keep them small


# RH Registry Token based auth
long_pass_test_registry:
label: rhregistry_tokenauth1
registry_url: https://registry.redhat.io
registry_username: # Username
registry_password: #Token or password needs to be > 255
repos_to_sync: [rhel7, rhel8/net-snmp, rhel7/etcd] # These really can be anything, just keep them small
67 changes: 67 additions & 0 deletions robottelo/config/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import os
import six
import yaml

from six.moves.urllib.parse import urlunsplit, urljoin
from six.moves.configparser import (
Expand Down Expand Up @@ -353,6 +354,71 @@ def validate(self):
return validation_errors


class ContainerRepositorySettings(FeatureSettings):
"""Settings for syncing containers from container registries"""
section = 'container_repo'

repo_config_required = ['label', 'registry_url', 'registry_username',
'registry_password', 'repos_to_sync']

def __init__(self, *args, **kwargs):
super(ContainerRepositorySettings, self).__init__(*args, **kwargs)
self.config_file = None
self.config = None
self.multi_registry_test_configs = None
self.yaml = None
self.long_pass_registry = None

def read(self, reader):
"""Read container repo settings and associated yaml file"""
self.config_file = reader.get(self.section, 'config_file')
if self.config_file:
with open(self.config_file) as cf:
self.yaml = yaml.safe_load(cf)
self.config = self.yaml.get(self.section, None)
if self.config:
self.long_pass_registry = self.config.get(
'long_pass_test_registry', None)
self.multi_registry_test_configs = self.config.get(
'multi_registry_test_configs', None)

def validate(self):
validation_errors = []
if not self.config_file:
validation_errors.append(
'[{}] config_file must be provided'.format(self.section))
elif not self.config:
validation_errors.append("{} contains no {} entry".format(self.config_file,
self.section))
else:
if not self.long_pass_registry:
validation_errors.append(
'[{}] contains no long_pass_registry'.format(self.section))
else:
validation_errors.extend(
self._validate_registry_configs([self.long_pass_registry]))

if not self.multi_registry_test_configs:
validation_errors.append(
'[{}] {} contains no multi_registry_test_configs'.format(
self.section, self.config_file))
else:
validation_errors.extend(self._validate_registry_configs(
self.multi_registry_test_configs))

return validation_errors

def _validate_registry_configs(self, configs):
validation_errors = []
for config in configs:
for req in self.repo_config_required:
if not config.get(req):
validation_errors.append(
'[{}] {} is required in {}'.format(self.section, req,
config))
return validation_errors


class DistroSettings(FeatureSettings):
"""Distro settings definitions."""
def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -1213,6 +1279,7 @@ def __init__(self):
self.certs = CertsSettings()
self.clients = ClientsSettings()
self.compute_resources = LibvirtHostSettings()
self.container_repo = ContainerRepositorySettings()
self.discovery = DiscoveryISOSettings()
self.distro = DistroSettings()
self.docker = DockerSettings()
Expand Down
83 changes: 83 additions & 0 deletions tests/foreman/api/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -2219,3 +2219,86 @@ def test_positive_symlinks_sync(self):
:CaseAutomation: notautomated
"""


class TokenAuthContainerRepositoryTestCase(APITestCase):
"""These test are similar to the ones in ``DockerRepositoryTestCase``,
but test with more container registries and registries that use
really long (>255 or >1024)tokens for passwords.
These test require container registry configs in container_repo.yaml
"""

@classmethod
def setUpClass(cls):
super(TokenAuthContainerRepositoryTestCase, cls).setUpClass()
cls.org = entities.Organization().create()

@tier2
def test_positive_create_with_long_token(self):
"""Create and sync Docker-type repo from the Red Hat Container registry
Using token based auth, with very long tokens (>255 characters).
:id: 79ce54cd-6353-457f-a6d1-08162a1bbe1d
:expectedresults: repo from registry with long password can be created
and synced
"""
# First we want to confirm the provided token is > 255 charaters
registry_config = settings.container_repo.long_pass_registry
self.assertGreater(len(registry_config['registry_password']), 255,
msg='Please use a longer (>255) token for '
'long_pass_test_registry')

product = entities.Product(organization=self.org).create()
for reponame in registry_config['repos_to_sync']:
with self.subTest(reponame):
repo = entities.Repository(
content_type=u'docker',
docker_upstream_name=reponame,
name=reponame,
product=product,
url=registry_config['registry_url'],
upstream_username=registry_config['registry_username'],
upstream_password=registry_config['registry_password']
).create()
self.assertEqual(repo.name, reponame)
self.assertEqual(repo.docker_upstream_name, reponame)
self.assertEqual(repo.content_type, u'docker')
self.assertEqual(repo.upstream_username,
registry_config['registry_username'])
repo.sync()
self.assertGreater(
repo.read().content_counts['docker_manifest'], 1)

@tier2
def test_positive_multi_registry(self):
"""Create and sync Docker-type repos from multiple supported registries
:id: 4f8ea85b-4c69-4da6-a8ef-bd467ee35147
:expectedresults: multiple products and repos are created
"""
for config in settings.container_repo.multi_registry_test_configs:
product_name = config['label']
with self.subTest(product_name):
product = entities.Product(organization=self.org,
name=product_name).create()

for repo_name in config['repos_to_sync']:
repo = entities.Repository(
content_type=u'docker',
docker_upstream_name=repo_name,
name=repo_name,
product=product,
url=config['registry_url'],
upstream_username=config['registry_username'],
upstream_password=config['registry_password']
).create()
self.assertEqual(repo.name, repo_name)
self.assertEqual(repo.docker_upstream_name, repo_name)
self.assertEqual(repo.content_type, u'docker')
self.assertEqual(repo.upstream_username,
config['registry_username'])
repo.sync()
self.assertGreater(
repo.read().content_counts['docker_manifest'], 1)

0 comments on commit 8362c64

Please sign in to comment.