{"action":"created","comment":{"url":"https://api.github.com/repos/autotest/autotest-docker/pulls/comments/64927105","id":64927105,"diff_hunk":"@@ -0,0 +1,333 @@\n+r\"\"\"\n+Summary\n+-------\n+\n+Test variations of 'docker login'\n+\n+Operational Summary\n+-------------------\n+\n+#. Create a self-signed SSL certificate\n+#. Install cert locally for use by docker daemon (FIXME:seems unnecessary)\n+#. Generate a pseudorandom password\n+#. Generate htpasswd file with a test user and this password\n+#. Run a registry container using new certificate & account\n+#. Run individual subtests against this standard setup\n+\"\"\"\n+\n+import os\n+from base64 import b64encode\n+import json\n+import urllib2\n+import time\n+from autotest.client import utils\n+from dockertest.containers import DockerContainers\n+from dockertest.images import DockerImages\n+from dockertest.subtest import SubSubtest\n+from dockertest.output import OutputGood\n+from dockertest.output import mustpass, mustfail\n+from dockertest.dockercmd import DockerCmd\n+from dockertest.xceptions import DockerTestFail\n+from dockertest import subtest\n+\n+\n+class login(subtest.SubSubtestCaller):\n+\n+    \"\"\" SubSubtest caller \"\"\"\n+\n+\n+class login_base(SubSubtest):\n+\n+    \"\"\" login base class; performs common setup. \"\"\"\n+\n+    def initialize(self):\n+        super(login_base, self).initialize()\n+\n+        # We need to create cert and htpasswd files for bind-mounting in\n+        # the registry container; do so in a safe temporary workdir.\n+        os.chdir(self.tmpdir)\n+\n+        # Creates domain.crt and domain.key files\n+        self._create_certs()\n+\n+        # Credentials: fixed username with pseudorandom password\n+        self._create_htpasswd()\n+\n+        self._preserve_docker_auth_file()\n+\n+        # Now run the registry itself, leave it running for the login test\n+        c_name = DockerContainers(self).get_unique_name()\n+        subargs = ['-d', '-p', '{port}:{port}'.format(**self.sub_stuff),\n+                   '--name', c_name,\n+                   '-v', '{}:/auth:Z'.format(self.tmpdir),\n+                   '-e', 'REGISTRY_HTTP_TLS_CERTIFICATE=/auth/domain.crt',\n+                   '-e', 'REGISTRY_HTTP_TLS_KEY=/auth/domain.key',\n+                   '-e', 'REGISTRY_AUTH=htpasswd',\n+                   '-e', 'REGISTRY_AUTH_HTPASSWD_REALM=\"Registry Realm\"',\n+                   '-e', 'REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd',\n+                   self.config['registry_fqin']]\n+        self.sub_stuff['my_containers'] = [c_name]\n+        mustpass(DockerCmd(self, 'run', subargs).execute())\n+        self._wait_for_registry_ready()\n+\n+    def _create_certs(self):\n+        \"\"\"\n+        Create a self-signed SSL certificate for use by the registry\n+        container (registry auth only works with TLS).\n+        \"\"\"\n+        localhost = 'localhost.localdomain'\n+        port = '5000'\n+        subj = '/C=US/ST=Foo/L=Bar/O=Red Hat, Inc./CN=%s' % localhost\n+        make_cert = ('openssl req -newkey rsa:4096 -nodes -sha256'\n+                     ' -keyout domain.key -x509 -days 2 -out domain.crt'\n+                     ' -subj \"%s\"' % subj)\n+        utils.run(make_cert, verbose=True)\n+\n+        self.sub_stuff['localhost'] = localhost\n+        self.sub_stuff['port'] = port\n+        self.sub_stuff['server'] = localhost + ':' + port\n+\n+    def _create_htpasswd(self):\n+        \"\"\"\n+        Write an htpasswd file in our current directory, for use by\n+        the registry container (via bind mount). Use the registry image\n+        itself to run htpasswd, with -n so output goes to stdout, then\n+        capture that stdout and write it to a file in our current directory.\n+        \"\"\"\n+        self.sub_stuff['user'] = 'testuser'\n+        self.sub_stuff['passwd'] = utils.generate_random_string(12)\n+\n+        registry_fqin = self.config['registry_fqin']\n+        subargs = ['--rm', '--entrypoint', 'htpasswd', registry_fqin,\n+                   '-Bbn', self.sub_stuff['user'], self.sub_stuff['passwd']]\n+        htpasswd_cmdresult = DockerCmd(self, 'run', subargs).execute()\n+        with open('htpasswd', 'wb') as htpasswd_fh:\n+            htpasswd_fh.write(htpasswd_cmdresult.stdout)\n+\n+    def _preserve_docker_auth_file(self):\n+        \"\"\"\n+        docker login creates/overwrites a standard file; preserve it\n+        if it already exists.","path":"subtests/docker_cli/login/login.py","position":110,"original_position":110,"commit_id":"da769b242702a176faec632a9198cb01589cb0e8","original_commit_id":"da769b242702a176faec632a9198cb01589cb0e8","user":{"login":"cevich","id":1183438,"avatar_url":"https://avatars.githubusercontent.com/u/1183438?v=3","gravatar_id":"","url":"https://api.github.com/users/cevich","html_url":"https://github.com/cevich","followers_url":"https://api.github.com/users/cevich/followers","following_url":"https://api.github.com/users/cevich/following{/other_user}","gists_url":"https://api.github.com/users/cevich/gists{/gist_id}","starred_url":"https://api.github.com/users/cevich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cevich/subscriptions","organizations_url":"https://api.github.com/users/cevich/orgs","repos_url":"https://api.github.com/users/cevich/repos","events_url":"https://api.github.com/users/cevich/events{/privacy}","received_events_url":"https://api.github.com/users/cevich/received_events","type":"User","site_admin":false},"body":"Awww so nice, thanks!  (and good catch)","created_at":"2016-05-27T15:58:01Z","updated_at":"2016-05-27T15:58:01Z","html_url":"https://github.com/autotest/autotest-docker/pull/605#discussion_r64927105","pull_request_url":"https://api.github.com/repos/autotest/autotest-docker/pulls/605","_links":{"self":{"href":"https://api.github.com/repos/autotest/autotest-docker/pulls/comments/64927105"},"html":{"href":"https://github.com/autotest/autotest-docker/pull/605#discussion_r64927105"},"pull_request":{"href":"https://api.github.com/repos/autotest/autotest-docker/pulls/605"}}},"pull_request":{"url":"https://api.github.com/repos/autotest/autotest-docker/pulls/605","id":71729969,"html_url":"https://github.com/autotest/autotest-docker/pull/605","diff_url":"https://github.com/autotest/autotest-docker/pull/605.diff","patch_url":"https://github.com/autotest/autotest-docker/pull/605.patch","issue_url":"https://api.github.com/repos/autotest/autotest-docker/issues/605","number":605,"state":"open","locked":false,"title":"Test docker login","user":{"login":"edsantiago","id":265639,"avatar_url":"https://avatars.githubusercontent.com/u/265639?v=3","gravatar_id":"","url":"https://api.github.com/users/edsantiago","html_url":"https://github.com/edsantiago","followers_url":"https://api.github.com/users/edsantiago/followers","following_url":"https://api.github.com/users/edsantiago/following{/other_user}","gists_url":"https://api.github.com/users/edsantiago/gists{/gist_id}","starred_url":"https://api.github.com/users/edsantiago/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edsantiago/subscriptions","organizations_url":"https://api.github.com/users/edsantiago/orgs","repos_url":"https://api.github.com/users/edsantiago/repos","events_url":"https://api.github.com/users/edsantiago/events{/privacy}","received_events_url":"https://api.github.com/users/edsantiago/received_events","type":"User","site_admin":false},"body":"Various forms of docker login/logout, including push with/without valid credentials.","created_at":"2016-05-27T15:21:46Z","updated_at":"2016-05-27T15:58:01Z","closed_at":null,"merged_at":null,"merge_commit_sha":"fd74eb0aecd7af45a94388000a1849c86c92f2d5","assignee":null,"milestone":{"url":"https://api.github.com/repos/autotest/autotest-docker/milestones/23","html_url":"https://github.com/autotest/autotest-docker/milestones/Docker%20Autotest%20Version%200.8.6%20(NO%20API%20Changes)","labels_url":"https://api.github.com/repos/autotest/autotest-docker/milestones/23/labels","id":1747813,"number":23,"title":"Docker Autotest Version 0.8.6 (NO API Changes)","description":"","creator":{"login":"cevich","id":1183438,"avatar_url":"https://avatars.githubusercontent.com/u/1183438?v=3","gravatar_id":"","url":"https://api.github.com/users/cevich","html_url":"https://github.com/cevich","followers_url":"https://api.github.com/users/cevich/followers","following_url":"https://api.github.com/users/cevich/following{/other_user}","gists_url":"https://api.github.com/users/cevich/gists{/gist_id}","starred_url":"https://api.github.com/users/cevich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cevich/subscriptions","organizations_url":"https://api.github.com/users/cevich/orgs","repos_url":"https://api.github.com/users/cevich/repos","events_url":"https://api.github.com/users/cevich/events{/privacy}","received_events_url":"https://api.github.com/users/cevich/received_events","type":"User","site_admin":false},"open_issues":42,"closed_issues":3,"state":"open","created_at":"2016-05-04T14:28:26Z","updated_at":"2016-05-27T15:52:17Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/autotest/autotest-docker/pulls/605/commits","review_comments_url":"https://api.github.com/repos/autotest/autotest-docker/pulls/605/comments","review_comment_url":"https://api.github.com/repos/autotest/autotest-docker/pulls/comments{/number}","comments_url":"https://api.github.com/repos/autotest/autotest-docker/issues/605/comments","statuses_url":"https://api.github.com/repos/autotest/autotest-docker/statuses/da769b242702a176faec632a9198cb01589cb0e8","head":{"label":"edsantiago:test-docker-login","ref":"test-docker-login","sha":"da769b242702a176faec632a9198cb01589cb0e8","user":{"login":"edsantiago","id":265639,"avatar_url":"https://avatars.githubusercontent.com/u/265639?v=3","gravatar_id":"","url":"https://api.github.com/users/edsantiago","html_url":"https://github.com/edsantiago","followers_url":"https://api.github.com/users/edsantiago/followers","following_url":"https://api.github.com/users/edsantiago/following{/other_user}","gists_url":"https://api.github.com/users/edsantiago/gists{/gist_id}","starred_url":"https://api.github.com/users/edsantiago/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edsantiago/subscriptions","organizations_url":"https://api.github.com/users/edsantiago/orgs","repos_url":"https://api.github.com/users/edsantiago/repos","events_url":"https://api.github.com/users/edsantiago/events{/privacy}","received_events_url":"https://api.github.com/users/edsantiago/received_events","type":"User","site_admin":false},"repo":{"id":51094257,"name":"autotest-docker","full_name":"edsantiago/autotest-docker","owner":{"login":"edsantiago","id":265639,"avatar_url":"https://avatars.githubusercontent.com/u/265639?v=3","gravatar_id":"","url":"https://api.github.com/users/edsantiago","html_url":"https://github.com/edsantiago","followers_url":"https://api.github.com/users/edsantiago/followers","following_url":"https://api.github.com/users/edsantiago/following{/other_user}","gists_url":"https://api.github.com/users/edsantiago/gists{/gist_id}","starred_url":"https://api.github.com/users/edsantiago/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edsantiago/subscriptions","organizations_url":"https://api.github.com/users/edsantiago/orgs","repos_url":"https://api.github.com/users/edsantiago/repos","events_url":"https://api.github.com/users/edsantiago/events{/privacy}","received_events_url":"https://api.github.com/users/edsantiago/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/edsantiago/autotest-docker","description":"Autotest client test containing functional & integration subtests for the Docker project","fork":true,"url":"https://api.github.com/repos/edsantiago/autotest-docker","forks_url":"https://api.github.com/repos/edsantiago/autotest-docker/forks","keys_url":"https://api.github.com/repos/edsantiago/autotest-docker/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edsantiago/autotest-docker/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edsantiago/autotest-docker/teams","hooks_url":"https://api.github.com/repos/edsantiago/autotest-docker/hooks","issue_events_url":"https://api.github.com/repos/edsantiago/autotest-docker/issues/events{/number}","events_url":"https://api.github.com/repos/edsantiago/autotest-docker/events","assignees_url":"https://api.github.com/repos/edsantiago/autotest-docker/assignees{/user}","branches_url":"https://api.github.com/repos/edsantiago/autotest-docker/branches{/branch}","tags_url":"https://api.github.com/repos/edsantiago/autotest-docker/tags","blobs_url":"https://api.github.com/repos/edsantiago/autotest-docker/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edsantiago/autotest-docker/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edsantiago/autotest-docker/git/refs{/sha}","trees_url":"https://api.github.com/repos/edsantiago/autotest-docker/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edsantiago/autotest-docker/statuses/{sha}","languages_url":"https://api.github.com/repos/edsantiago/autotest-docker/languages","stargazers_url":"https://api.github.com/repos/edsantiago/autotest-docker/stargazers","contributors_url":"https://api.github.com/repos/edsantiago/autotest-docker/contributors","subscribers_url":"https://api.github.com/repos/edsantiago/autotest-docker/subscribers","subscription_url":"https://api.github.com/repos/edsantiago/autotest-docker/subscription","commits_url":"https://api.github.com/repos/edsantiago/autotest-docker/commits{/sha}","git_commits_url":"https://api.github.com/repos/edsantiago/autotest-docker/git/commits{/sha}","comments_url":"https://api.github.com/repos/edsantiago/autotest-docker/comments{/number}","issue_comment_url":"https://api.github.com/repos/edsantiago/autotest-docker/issues/comments{/number}","contents_url":"https://api.github.com/repos/edsantiago/autotest-docker/contents/{+path}","compare_url":"https://api.github.com/repos/edsantiago/autotest-docker/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edsantiago/autotest-docker/merges","archive_url":"https://api.github.com/repos/edsantiago/autotest-docker/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edsantiago/autotest-docker/downloads","issues_url":"https://api.github.com/repos/edsantiago/autotest-docker/issues{/number}","pulls_url":"https://api.github.com/repos/edsantiago/autotest-docker/pulls{/number}","milestones_url":"https://api.github.com/repos/edsantiago/autotest-docker/milestones{/number}","notifications_url":"https://api.github.com/repos/edsantiago/autotest-docker/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edsantiago/autotest-docker/labels{/name}","releases_url":"https://api.github.com/repos/edsantiago/autotest-docker/releases{/id}","deployments_url":"https://api.github.com/repos/edsantiago/autotest-docker/deployments","created_at":"2016-02-04T17:56:14Z","updated_at":"2016-02-04T17:56:15Z","pushed_at":"2016-05-27T15:20:40Z","git_url":"git://github.com/edsantiago/autotest-docker.git","ssh_url":"git@github.com:edsantiago/autotest-docker.git","clone_url":"https://github.com/edsantiago/autotest-docker.git","svn_url":"https://github.com/edsantiago/autotest-docker","homepage":null,"size":2142,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"autotest:master","ref":"master","sha":"4f5cbf583f8038b20a96262d1dc485871800456b","user":{"login":"autotest","id":472856,"avatar_url":"https://avatars.githubusercontent.com/u/472856?v=3","gravatar_id":"","url":"https://api.github.com/users/autotest","html_url":"https://github.com/autotest","followers_url":"https://api.github.com/users/autotest/followers","following_url":"https://api.github.com/users/autotest/following{/other_user}","gists_url":"https://api.github.com/users/autotest/gists{/gist_id}","starred_url":"https://api.github.com/users/autotest/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/autotest/subscriptions","organizations_url":"https://api.github.com/users/autotest/orgs","repos_url":"https://api.github.com/users/autotest/repos","events_url":"https://api.github.com/users/autotest/events{/privacy}","received_events_url":"https://api.github.com/users/autotest/received_events","type":"Organization","site_admin":false},"repo":{"id":17869790,"name":"autotest-docker","full_name":"autotest/autotest-docker","owner":{"login":"autotest","id":472856,"avatar_url":"https://avatars.githubusercontent.com/u/472856?v=3","gravatar_id":"","url":"https://api.github.com/users/autotest","html_url":"https://github.com/autotest","followers_url":"https://api.github.com/users/autotest/followers","following_url":"https://api.github.com/users/autotest/following{/other_user}","gists_url":"https://api.github.com/users/autotest/gists{/gist_id}","starred_url":"https://api.github.com/users/autotest/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/autotest/subscriptions","organizations_url":"https://api.github.com/users/autotest/orgs","repos_url":"https://api.github.com/users/autotest/repos","events_url":"https://api.github.com/users/autotest/events{/privacy}","received_events_url":"https://api.github.com/users/autotest/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/autotest/autotest-docker","description":"Autotest client test containing functional & integration subtests for the Docker project","fork":false,"url":"https://api.github.com/repos/autotest/autotest-docker","forks_url":"https://api.github.com/repos/autotest/autotest-docker/forks","keys_url":"https://api.github.com/repos/autotest/autotest-docker/keys{/key_id}","collaborators_url":"https://api.github.com/repos/autotest/autotest-docker/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/autotest/autotest-docker/teams","hooks_url":"https://api.github.com/repos/autotest/autotest-docker/hooks","issue_events_url":"https://api.github.com/repos/autotest/autotest-docker/issues/events{/number}","events_url":"https://api.github.com/repos/autotest/autotest-docker/events","assignees_url":"https://api.github.com/repos/autotest/autotest-docker/assignees{/user}","branches_url":"https://api.github.com/repos/autotest/autotest-docker/branches{/branch}","tags_url":"https://api.github.com/repos/autotest/autotest-docker/tags","blobs_url":"https://api.github.com/repos/autotest/autotest-docker/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/autotest/autotest-docker/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/autotest/autotest-docker/git/refs{/sha}","trees_url":"https://api.github.com/repos/autotest/autotest-docker/git/trees{/sha}","statuses_url":"https://api.github.com/repos/autotest/autotest-docker/statuses/{sha}","languages_url":"https://api.github.com/repos/autotest/autotest-docker/languages","stargazers_url":"https://api.github.com/repos/autotest/autotest-docker/stargazers","contributors_url":"https://api.github.com/repos/autotest/autotest-docker/contributors","subscribers_url":"https://api.github.com/repos/autotest/autotest-docker/subscribers","subscription_url":"https://api.github.com/repos/autotest/autotest-docker/subscription","commits_url":"https://api.github.com/repos/autotest/autotest-docker/commits{/sha}","git_commits_url":"https://api.github.com/repos/autotest/autotest-docker/git/commits{/sha}","comments_url":"https://api.github.com/repos/autotest/autotest-docker/comments{/number}","issue_comment_url":"https://api.github.com/repos/autotest/autotest-docker/issues/comments{/number}","contents_url":"https://api.github.com/repos/autotest/autotest-docker/contents/{+path}","compare_url":"https://api.github.com/repos/autotest/autotest-docker/compare/{base}...{head}","merges_url":"https://api.github.com/repos/autotest/autotest-docker/merges","archive_url":"https://api.github.com/repos/autotest/autotest-docker/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/autotest/autotest-docker/downloads","issues_url":"https://api.github.com/repos/autotest/autotest-docker/issues{/number}","pulls_url":"https://api.github.com/repos/autotest/autotest-docker/pulls{/number}","milestones_url":"https://api.github.com/repos/autotest/autotest-docker/milestones{/number}","notifications_url":"https://api.github.com/repos/autotest/autotest-docker/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/autotest/autotest-docker/labels{/name}","releases_url":"https://api.github.com/repos/autotest/autotest-docker/releases{/id}","deployments_url":"https://api.github.com/repos/autotest/autotest-docker/deployments","created_at":"2014-03-18T14:53:27Z","updated_at":"2016-04-27T17:35:16Z","pushed_at":"2016-05-27T15:21:47Z","git_url":"git://github.com/autotest/autotest-docker.git","ssh_url":"git@github.com:autotest/autotest-docker.git","clone_url":"https://github.com/autotest/autotest-docker.git","svn_url":"https://github.com/autotest/autotest-docker","homepage":null,"size":2641,"stargazers_count":11,"watchers_count":11,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":22,"mirror_url":null,"open_issues_count":54,"forks":22,"open_issues":54,"watchers":11,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/autotest/autotest-docker/pulls/605"},"html":{"href":"https://github.com/autotest/autotest-docker/pull/605"},"issue":{"href":"https://api.github.com/repos/autotest/autotest-docker/issues/605"},"comments":{"href":"https://api.github.com/repos/autotest/autotest-docker/issues/605/comments"},"review_comments":{"href":"https://api.github.com/repos/autotest/autotest-docker/pulls/605/comments"},"review_comment":{"href":"https://api.github.com/repos/autotest/autotest-docker/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/autotest/autotest-docker/pulls/605/commits"},"statuses":{"href":"https://api.github.com/repos/autotest/autotest-docker/statuses/da769b242702a176faec632a9198cb01589cb0e8"}}}}
{"actor":{"display_login":"cevich"}}