Skip to content
This repository has been archived by the owner on Dec 7, 2022. It is now read-only.

Adding logic for registering and updating consumers with client certs #28

Merged
merged 1 commit into from Aug 16, 2018

Conversation

ragabala
Copy link
Contributor

This commit adds a new testcase for registering and updating a consumer.
The Registering happens with basic auth url and the update is through
the client certificate that is in the previous response.

See pulp/pulp-smash#1007

Copy link
Contributor

@Ichimonji10 Ichimonji10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address comments.

with self.subTest(comment='check response body'):
self.assertEqual(result['display_name'], body['delta']['display_name'])
self.assertEqual(result['notes'], body['delta']['notes'])
self.assertEqual(result['description'], body['delta']['description'])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about putting each of these three assertions into separate subtests?

"""Show that one can `register and update a consumer`_.

The call to `consumer register api` should return a x.509 certificate,
that should be useful in updating a consumer and for other actions.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dedent this text.

class RegisterAndUpdateConsumerTestCase(unittest.TestCase):
"""Show that one can `register and update a consumer`_.

The call to `consumer register api` should return a x.509 certificate,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't how to create a link:

My `link`.

This is:

My `link`_.

consumer = client.post(CONSUMERS_PATH, {'id': utils.uuid4()}).json()
self.addCleanup(client.delete, consumer['consumer']['_href'])
with self.subTest(comment='check register call returns with certificate'):
self.assertIn('certificate', consumer)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see this code below:

certificate = consumer['certificate']

So why is this test continuing even when "certificate" isn't in the "consumer" dict? Drop the surrounding subTest.

tmp_cert_file = tempfile.NamedTemporaryFile(delete=False)
self.addCleanup(os.unlink, tmp_cert_file.name)
with open(tmp_cert_file.name, 'w') as file_writer:
file_writer.write(certificate)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't mangle my bare-metal host! This creates files on the host that's running Pulp Smash, not the host under test.

@@ -0,0 +1,29 @@
# coding=utf-8
"""Utility functions for Platform tests."""

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: drop this blank line.

# Step 2
certificate = consumer['certificate']
tmp_cert_file = tempfile.NamedTemporaryFile(delete=False)
self.addCleanup(os.unlink, tmp_cert_file.name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't mangle my bare-metal host!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Ichimonji10,

This is a client-side certificate. A certificate file is needed for testing this test case. The certificate is created as a temp file which is cleaned up as soon as the test completes by the self.addCleanup , thus the file wont exist once the test completes (either pass/fail). Is there any other workaround rather than creating a file?

Copy link
Contributor

@Ichimonji10 Ichimonji10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pulp_2_tests/tests/platform/api_v2/utils.py is a brand new module, and it needs to be included in the docs. Run make docs-html and fix the issues reported by Sphinx.

from pulp_smash import api


def make_client_with_cert_auth(cfg, cert=None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is cert an optional parameter?

class RegisterAndUpdateConsumerTestCase(unittest.TestCase):
"""Show that one can `register and update a consumer`_.

The call to ``consumer register api`` should return a x.509 certificate,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is "consumer register api" code?

client = api.Client(cfg)

# Step 1
consumer = client.post(CONSUMERS_PATH, {'id': utils.uuid4()}).json()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add a gen_consumer function and use it in cases like this. It doesn't need to be done as part of this PR.

file_writer.write(certificate)

# step 3
new_client = make_client_with_cert_auth(cfg, cert=tmp_cert_file.name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than making a new client, how about mutating the existing client object?

* `Pulp Smash #1007 <https://github.com/PulpQE/pulp-smash/issues/1007>`_
"""
cfg = config.get_config()
client = api.Client(cfg)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about passing api.json_handler as the response handler?

This commit adds a new testcase for registering and updating a consumer.
The Registering happens with basic auth url and the update is through
the client certificate that is in the previous response.

See pulp/pulp-smash#1007
Copy link
Contributor

@Ichimonji10 Ichimonji10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

@Ichimonji10 Ichimonji10 merged commit 4ffd0bf into pulp:master Aug 16, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants