{"action":"created","comment":{"url":"https://api.github.com/repos/docker/notary/pulls/comments/46746552","id":46746552,"diff_hunk":"@@ -0,0 +1,209 @@\n+package snapshot\n+\n+import (\n+\t\"bytes\"\n+\t\"encoding/json\"\n+\t\"testing\"\n+\t\"time\"\n+\n+\t\"github.com/stretchr/testify/assert\"\n+\n+\t\"github.com/docker/notary/server/storage\"\n+\t\"github.com/docker/notary/tuf/data\"\n+\t\"github.com/docker/notary/tuf/signed\"\n+)\n+\n+func TestSnapshotExpired(t *testing.T) {\n+\tsn := &data.SignedSnapshot{\n+\t\tSignatures: nil,\n+\t\tSigned: data.Snapshot{\n+\t\t\tExpires: time.Now().AddDate(-1, 0, 0),\n+\t\t},\n+\t}\n+\tassert.True(t, snapshotExpired(sn), \"Snapshot should have expired\")\n+}\n+\n+func TestSnapshotNotExpired(t *testing.T) {\n+\tsn := &data.SignedSnapshot{\n+\t\tSignatures: nil,\n+\t\tSigned: data.Snapshot{\n+\t\t\tExpires: time.Now().AddDate(1, 0, 0),\n+\t\t},\n+\t}\n+\tassert.False(t, snapshotExpired(sn), \"Snapshot should NOT have expired\")\n+}\n+\n+func TestGetSnapshotKeyCreate(t *testing.T) {\n+\tstore := storage.NewMemStorage()\n+\tcrypto := signed.NewEd25519()\n+\tk, err := GetOrCreateSnapshotKey(\"gun\", store, crypto, data.ED25519Key)\n+\tassert.Nil(t, err, \"Expected nil error\")\n+\tassert.NotNil(t, k, \"Key should not be nil\")\n+\n+\tk2, err := GetOrCreateSnapshotKey(\"gun\", store, crypto, data.ED25519Key)\n+\n+\tassert.Nil(t, err, \"Expected nil error\")\n+\n+\t// trying to get the same key again should return the same value\n+\tassert.Equal(t, k, k2, \"Did not receive same key when attempting to recreate.\")\n+\tassert.NotNil(t, k2, \"Key should not be nil\")\n+}\n+\n+func TestGetSnapshotKeyExisting(t *testing.T) {\n+\tstore := storage.NewMemStorage()\n+\tcrypto := signed.NewEd25519()\n+\tkey, err := crypto.Create(data.CanonicalSnapshotRole, data.ED25519Key)\n+\tassert.NoError(t, err)\n+\n+\tstore.SetKey(\"gun\", data.CanonicalSnapshotRole, data.ED25519Key, key.Public())\n+\n+\tk, err := GetOrCreateSnapshotKey(\"gun\", store, crypto, data.ED25519Key)\n+\tassert.Nil(t, err, \"Expected nil error\")\n+\tassert.NotNil(t, k, \"Key should not be nil\")\n+\tassert.Equal(t, key, k, \"Did not receive same key when attempting to recreate.\")\n+\tassert.NotNil(t, k, \"Key should not be nil\")\n+\n+\tk2, err := GetOrCreateSnapshotKey(\"gun\", store, crypto, data.ED25519Key)\n+\n+\tassert.Nil(t, err, \"Expected nil error\")\n+\n+\t// trying to get the same key again should return the same value\n+\tassert.Equal(t, k, k2, \"Did not receive same key when attempting to recreate.\")\n+\tassert.NotNil(t, k2, \"Key should not be nil\")\n+}\n+\n+type keyStore struct {\n+\tgetCalled bool\n+\tk         data.PublicKey\n+}\n+\n+func (ks *keyStore) GetKey(gun, role string) (string, []byte, error) {\n+\tdefer func() { ks.getCalled = true }()\n+\tif ks.getCalled {\n+\t\treturn ks.k.Algorithm(), ks.k.Public(), nil\n+\t}\n+\treturn \"\", nil, &storage.ErrNoKey{}\n+}\n+\n+func (ks keyStore) SetKey(gun, role, algorithm string, public []byte) error {\n+\treturn &storage.ErrKeyExists{}\n+}\n+\n+func TestGetSnapshotKeyExistsOnSet(t *testing.T) {\n+\tcrypto := signed.NewEd25519()\n+\tkey, err := crypto.Create(data.CanonicalSnapshotRole, data.ED25519Key)\n+\tassert.NoError(t, err)\n+\tstore := &keyStore{k: key}\n+\n+\tk, err := GetOrCreateSnapshotKey(\"gun\", store, crypto, data.ED25519Key)\n+\tassert.Nil(t, err, \"Expected nil error\")\n+\tassert.NotNil(t, k, \"Key should not be nil\")\n+\tassert.Equal(t, key, k, \"Did not receive same key when attempting to recreate.\")\n+\tassert.NotNil(t, k, \"Key should not be nil\")\n+\n+\tk2, err := GetOrCreateSnapshotKey(\"gun\", store, crypto, data.ED25519Key)\n+\n+\tassert.Nil(t, err, \"Expected nil error\")\n+\n+\t// trying to get the same key again should return the same value\n+\tassert.Equal(t, k, k2, \"Did not receive same key when attempting to recreate.\")\n+\tassert.NotNil(t, k2, \"Key should not be nil\")\n+}\n+\n+func TestRoleExpired(t *testing.T) {\n+\tmeta := data.FileMeta{\n+\t\tHashes: data.Hashes{\n+\t\t\t\"sha256\": []byte{1},\n+\t\t},\n+\t}\n+\tnewData := []byte{2}\n+\tres, _ := roleExpired(newData, meta)\n+\tassert.True(t, res)\n+}\n+\n+func TestRoleNotExpired(t *testing.T) {\n+\tnewData := []byte{2}\n+\tcurrMeta, err := data.NewFileMeta(bytes.NewReader(newData), \"sha256\")\n+\tassert.NoError(t, err)\n+\n+\tmeta := data.FileMeta{\n+\t\tHashes: data.Hashes{\n+\t\t\t\"sha256\": currMeta.Hashes[\"sha256\"],\n+\t\t},\n+\t}\n+\n+\tres, _ := roleExpired(newData, meta)\n+\tassert.False(t, res)\n+}\n+\n+func TestGetSnapshotNotExists(t *testing.T) {\n+\tstore := storage.NewMemStorage()\n+\tcrypto := signed.NewEd25519()\n+\n+\t_, err := GetOrCreateSnapshot(\"gun\", store, crypto)\n+\tassert.Error(t, err)\n+}\n+\n+func TestGetSnapshotCurrValid(t *testing.T) {\n+\tstore := storage.NewMemStorage()\n+\tcrypto := signed.NewEd25519()\n+\n+\t_, err := GetOrCreateSnapshotKey(\"gun\", store, crypto, data.ED25519Key)\n+\n+\tnewData := []byte{2}\n+\tcurrMeta, err := data.NewFileMeta(bytes.NewReader(newData), \"sha256\")\n+\tassert.NoError(t, err)\n+\n+\tsnapshot := &data.SignedSnapshot{\n+\t\tSigned: data.Snapshot{\n+\t\t\tExpires: data.DefaultExpires(data.CanonicalSnapshotRole),\n+\t\t\tMeta: data.Files{\n+\t\t\t\tdata.CanonicalRootRole: currMeta,\n+\t\t\t},\n+\t\t},\n+\t}\n+\tsnapJSON, _ := json.Marshal(snapshot)\n+\n+\t// test when db is missing the role data\n+\tstore.UpdateCurrent(\"gun\", storage.MetaUpdate{Role: \"snapshot\", Version: 0, Data: snapJSON})\n+\t_, err = GetOrCreateSnapshot(\"gun\", store, crypto)\n+\tassert.NoError(t, err)\n+\n+\t// test when db has the role data\n+\tstore.UpdateCurrent(\"gun\", storage.MetaUpdate{Role: \"root\", Version: 0, Data: newData})\n+\t_, err = GetOrCreateSnapshot(\"gun\", store, crypto)\n+\tassert.NoError(t, err)\n+\n+\t// test when db role data is expired\n+\tstore.UpdateCurrent(\"gun\", storage.MetaUpdate{Role: \"root\", Version: 1, Data: []byte{3}})\n+\t_, err = GetOrCreateSnapshot(\"gun\", store, crypto)\n+\tassert.NoError(t, err)\n+}\n+\n+func TestGetSnapshotCurrExpired(t *testing.T) {","path":"server/snapshot/snapshot_test.go","position":183,"original_position":183,"commit_id":"7624d9884bbcaae5aec84773980964b9ec147f86","original_commit_id":"34f748f14c383bf7e5435c58db1b36d1543d86f6","user":{"login":"endophage","id":1302091,"avatar_url":"https://avatars.githubusercontent.com/u/1302091?v=3","gravatar_id":"","url":"https://api.github.com/users/endophage","html_url":"https://github.com/endophage","followers_url":"https://api.github.com/users/endophage/followers","following_url":"https://api.github.com/users/endophage/following{/other_user}","gists_url":"https://api.github.com/users/endophage/gists{/gist_id}","starred_url":"https://api.github.com/users/endophage/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/endophage/subscriptions","organizations_url":"https://api.github.com/users/endophage/orgs","repos_url":"https://api.github.com/users/endophage/repos","events_url":"https://api.github.com/users/endophage/events{/privacy}","received_events_url":"https://api.github.com/users/endophage/received_events","type":"User","site_admin":false},"body":"See line 177 just above :-)","created_at":"2015-12-04T23:48:55Z","updated_at":"2015-12-04T23:48:55Z","html_url":"https://github.com/docker/notary/pull/332#discussion_r46746552","pull_request_url":"https://api.github.com/repos/docker/notary/pulls/332","_links":{"self":{"href":"https://api.github.com/repos/docker/notary/pulls/comments/46746552"},"html":{"href":"https://github.com/docker/notary/pull/332#discussion_r46746552"},"pull_request":{"href":"https://api.github.com/repos/docker/notary/pulls/332"}}},"pull_request":{"url":"https://api.github.com/repos/docker/notary/pulls/332","id":52579020,"html_url":"https://github.com/docker/notary/pull/332","diff_url":"https://github.com/docker/notary/pull/332.diff","patch_url":"https://github.com/docker/notary/pull/332.patch","issue_url":"https://api.github.com/repos/docker/notary/issues/332","number":332,"state":"open","locked":false,"title":"WIP: Server snapshot","user":{"login":"endophage","id":1302091,"avatar_url":"https://avatars.githubusercontent.com/u/1302091?v=3","gravatar_id":"","url":"https://api.github.com/users/endophage","html_url":"https://github.com/endophage","followers_url":"https://api.github.com/users/endophage/followers","following_url":"https://api.github.com/users/endophage/following{/other_user}","gists_url":"https://api.github.com/users/endophage/gists{/gist_id}","starred_url":"https://api.github.com/users/endophage/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/endophage/subscriptions","organizations_url":"https://api.github.com/users/endophage/orgs","repos_url":"https://api.github.com/users/endophage/repos","events_url":"https://api.github.com/users/endophage/events{/privacy}","received_events_url":"https://api.github.com/users/endophage/received_events","type":"User","site_admin":false},"body":"This builds on top of #329 to add optional server side snapshotting.","created_at":"2015-12-03T19:19:45Z","updated_at":"2015-12-04T23:48:55Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d7bca27532fb35d8453649c87c8d725105a7e4ce","assignee":{"login":"endophage","id":1302091,"avatar_url":"https://avatars.githubusercontent.com/u/1302091?v=3","gravatar_id":"","url":"https://api.github.com/users/endophage","html_url":"https://github.com/endophage","followers_url":"https://api.github.com/users/endophage/followers","following_url":"https://api.github.com/users/endophage/following{/other_user}","gists_url":"https://api.github.com/users/endophage/gists{/gist_id}","starred_url":"https://api.github.com/users/endophage/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/endophage/subscriptions","organizations_url":"https://api.github.com/users/endophage/orgs","repos_url":"https://api.github.com/users/endophage/repos","events_url":"https://api.github.com/users/endophage/events{/privacy}","received_events_url":"https://api.github.com/users/endophage/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/docker/notary/pulls/332/commits","review_comments_url":"https://api.github.com/repos/docker/notary/pulls/332/comments","review_comment_url":"https://api.github.com/repos/docker/notary/pulls/comments{/number}","comments_url":"https://api.github.com/repos/docker/notary/issues/332/comments","statuses_url":"https://api.github.com/repos/docker/notary/statuses/7624d9884bbcaae5aec84773980964b9ec147f86","head":{"label":"endophage:server_snapshot","ref":"server_snapshot","sha":"7624d9884bbcaae5aec84773980964b9ec147f86","user":{"login":"endophage","id":1302091,"avatar_url":"https://avatars.githubusercontent.com/u/1302091?v=3","gravatar_id":"","url":"https://api.github.com/users/endophage","html_url":"https://github.com/endophage","followers_url":"https://api.github.com/users/endophage/followers","following_url":"https://api.github.com/users/endophage/following{/other_user}","gists_url":"https://api.github.com/users/endophage/gists{/gist_id}","starred_url":"https://api.github.com/users/endophage/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/endophage/subscriptions","organizations_url":"https://api.github.com/users/endophage/orgs","repos_url":"https://api.github.com/users/endophage/repos","events_url":"https://api.github.com/users/endophage/events{/privacy}","received_events_url":"https://api.github.com/users/endophage/received_events","type":"User","site_admin":false},"repo":{"id":37937558,"name":"notary","full_name":"endophage/notary","owner":{"login":"endophage","id":1302091,"avatar_url":"https://avatars.githubusercontent.com/u/1302091?v=3","gravatar_id":"","url":"https://api.github.com/users/endophage","html_url":"https://github.com/endophage","followers_url":"https://api.github.com/users/endophage/followers","following_url":"https://api.github.com/users/endophage/following{/other_user}","gists_url":"https://api.github.com/users/endophage/gists{/gist_id}","starred_url":"https://api.github.com/users/endophage/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/endophage/subscriptions","organizations_url":"https://api.github.com/users/endophage/orgs","repos_url":"https://api.github.com/users/endophage/repos","events_url":"https://api.github.com/users/endophage/events{/privacy}","received_events_url":"https://api.github.com/users/endophage/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/endophage/notary","description":"","fork":true,"url":"https://api.github.com/repos/endophage/notary","forks_url":"https://api.github.com/repos/endophage/notary/forks","keys_url":"https://api.github.com/repos/endophage/notary/keys{/key_id}","collaborators_url":"https://api.github.com/repos/endophage/notary/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/endophage/notary/teams","hooks_url":"https://api.github.com/repos/endophage/notary/hooks","issue_events_url":"https://api.github.com/repos/endophage/notary/issues/events{/number}","events_url":"https://api.github.com/repos/endophage/notary/events","assignees_url":"https://api.github.com/repos/endophage/notary/assignees{/user}","branches_url":"https://api.github.com/repos/endophage/notary/branches{/branch}","tags_url":"https://api.github.com/repos/endophage/notary/tags","blobs_url":"https://api.github.com/repos/endophage/notary/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/endophage/notary/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/endophage/notary/git/refs{/sha}","trees_url":"https://api.github.com/repos/endophage/notary/git/trees{/sha}","statuses_url":"https://api.github.com/repos/endophage/notary/statuses/{sha}","languages_url":"https://api.github.com/repos/endophage/notary/languages","stargazers_url":"https://api.github.com/repos/endophage/notary/stargazers","contributors_url":"https://api.github.com/repos/endophage/notary/contributors","subscribers_url":"https://api.github.com/repos/endophage/notary/subscribers","subscription_url":"https://api.github.com/repos/endophage/notary/subscription","commits_url":"https://api.github.com/repos/endophage/notary/commits{/sha}","git_commits_url":"https://api.github.com/repos/endophage/notary/git/commits{/sha}","comments_url":"https://api.github.com/repos/endophage/notary/comments{/number}","issue_comment_url":"https://api.github.com/repos/endophage/notary/issues/comments{/number}","contents_url":"https://api.github.com/repos/endophage/notary/contents/{+path}","compare_url":"https://api.github.com/repos/endophage/notary/compare/{base}...{head}","merges_url":"https://api.github.com/repos/endophage/notary/merges","archive_url":"https://api.github.com/repos/endophage/notary/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/endophage/notary/downloads","issues_url":"https://api.github.com/repos/endophage/notary/issues{/number}","pulls_url":"https://api.github.com/repos/endophage/notary/pulls{/number}","milestones_url":"https://api.github.com/repos/endophage/notary/milestones{/number}","notifications_url":"https://api.github.com/repos/endophage/notary/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/endophage/notary/labels{/name}","releases_url":"https://api.github.com/repos/endophage/notary/releases{/id}","created_at":"2015-06-23T18:35:21Z","updated_at":"2015-06-23T18:35:27Z","pushed_at":"2015-12-04T23:44:07Z","git_url":"git://github.com/endophage/notary.git","ssh_url":"git@github.com:endophage/notary.git","clone_url":"https://github.com/endophage/notary.git","svn_url":"https://github.com/endophage/notary","homepage":"","size":21708,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"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":"docker:master","ref":"master","sha":"52aa55076befc77bfdfd359a756a9a9a99407c57","user":{"login":"docker","id":5429470,"avatar_url":"https://avatars.githubusercontent.com/u/5429470?v=3","gravatar_id":"","url":"https://api.github.com/users/docker","html_url":"https://github.com/docker","followers_url":"https://api.github.com/users/docker/followers","following_url":"https://api.github.com/users/docker/following{/other_user}","gists_url":"https://api.github.com/users/docker/gists{/gist_id}","starred_url":"https://api.github.com/users/docker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/docker/subscriptions","organizations_url":"https://api.github.com/users/docker/orgs","repos_url":"https://api.github.com/users/docker/repos","events_url":"https://api.github.com/users/docker/events{/privacy}","received_events_url":"https://api.github.com/users/docker/received_events","type":"Organization","site_admin":false},"repo":{"id":37743436,"name":"notary","full_name":"docker/notary","owner":{"login":"docker","id":5429470,"avatar_url":"https://avatars.githubusercontent.com/u/5429470?v=3","gravatar_id":"","url":"https://api.github.com/users/docker","html_url":"https://github.com/docker","followers_url":"https://api.github.com/users/docker/followers","following_url":"https://api.github.com/users/docker/following{/other_user}","gists_url":"https://api.github.com/users/docker/gists{/gist_id}","starred_url":"https://api.github.com/users/docker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/docker/subscriptions","organizations_url":"https://api.github.com/users/docker/orgs","repos_url":"https://api.github.com/users/docker/repos","events_url":"https://api.github.com/users/docker/events{/privacy}","received_events_url":"https://api.github.com/users/docker/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/docker/notary","description":"","fork":false,"url":"https://api.github.com/repos/docker/notary","forks_url":"https://api.github.com/repos/docker/notary/forks","keys_url":"https://api.github.com/repos/docker/notary/keys{/key_id}","collaborators_url":"https://api.github.com/repos/docker/notary/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/docker/notary/teams","hooks_url":"https://api.github.com/repos/docker/notary/hooks","issue_events_url":"https://api.github.com/repos/docker/notary/issues/events{/number}","events_url":"https://api.github.com/repos/docker/notary/events","assignees_url":"https://api.github.com/repos/docker/notary/assignees{/user}","branches_url":"https://api.github.com/repos/docker/notary/branches{/branch}","tags_url":"https://api.github.com/repos/docker/notary/tags","blobs_url":"https://api.github.com/repos/docker/notary/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/docker/notary/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/docker/notary/git/refs{/sha}","trees_url":"https://api.github.com/repos/docker/notary/git/trees{/sha}","statuses_url":"https://api.github.com/repos/docker/notary/statuses/{sha}","languages_url":"https://api.github.com/repos/docker/notary/languages","stargazers_url":"https://api.github.com/repos/docker/notary/stargazers","contributors_url":"https://api.github.com/repos/docker/notary/contributors","subscribers_url":"https://api.github.com/repos/docker/notary/subscribers","subscription_url":"https://api.github.com/repos/docker/notary/subscription","commits_url":"https://api.github.com/repos/docker/notary/commits{/sha}","git_commits_url":"https://api.github.com/repos/docker/notary/git/commits{/sha}","comments_url":"https://api.github.com/repos/docker/notary/comments{/number}","issue_comment_url":"https://api.github.com/repos/docker/notary/issues/comments{/number}","contents_url":"https://api.github.com/repos/docker/notary/contents/{+path}","compare_url":"https://api.github.com/repos/docker/notary/compare/{base}...{head}","merges_url":"https://api.github.com/repos/docker/notary/merges","archive_url":"https://api.github.com/repos/docker/notary/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/docker/notary/downloads","issues_url":"https://api.github.com/repos/docker/notary/issues{/number}","pulls_url":"https://api.github.com/repos/docker/notary/pulls{/number}","milestones_url":"https://api.github.com/repos/docker/notary/milestones{/number}","notifications_url":"https://api.github.com/repos/docker/notary/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/docker/notary/labels{/name}","releases_url":"https://api.github.com/repos/docker/notary/releases{/id}","created_at":"2015-06-19T20:07:53Z","updated_at":"2015-12-01T14:37:41Z","pushed_at":"2015-12-04T23:44:08Z","git_url":"git://github.com/docker/notary.git","ssh_url":"git@github.com:docker/notary.git","clone_url":"https://github.com/docker/notary.git","svn_url":"https://github.com/docker/notary","homepage":null,"size":21896,"stargazers_count":442,"watchers_count":442,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":61,"mirror_url":null,"open_issues_count":43,"forks":61,"open_issues":43,"watchers":442,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/docker/notary/pulls/332"},"html":{"href":"https://github.com/docker/notary/pull/332"},"issue":{"href":"https://api.github.com/repos/docker/notary/issues/332"},"comments":{"href":"https://api.github.com/repos/docker/notary/issues/332/comments"},"review_comments":{"href":"https://api.github.com/repos/docker/notary/pulls/332/comments"},"review_comment":{"href":"https://api.github.com/repos/docker/notary/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/docker/notary/pulls/332/commits"},"statuses":{"href":"https://api.github.com/repos/docker/notary/statuses/7624d9884bbcaae5aec84773980964b9ec147f86"}}}}