Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some content trust tests #924

Merged
merged 1 commit into from
Mar 19, 2018
Merged

Conversation

vdemeester
Copy link
Collaborator

@vdemeester vdemeester commented Mar 7, 2018

Importing from moby's DockerTrustSuite tests.

This is still wip since there is some tests that are failing and some empty tests I did not yet migrate.
Also, there has been some slight changes between 17.06 and current docker/cli, so one some behavior, I'm not sure if it's supposed to fail or not (cc @n4ss @endophage)

See moby/moby#36515 for original tests that are supposed to be migrated.

Probably require #929 to be able to write unit tests for content trust..

Signed-off-by: Vincent Demeester vincent@sbr.pm

@@ -17,5 +17,14 @@ services:
- notary-fixtures:/fixtures
command: ['notary-server', '-config=/fixtures/notary-config.json']

evil-notary-server:
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 it evil?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

See https://github.com/moby/moby/pull/36515/files#diff-4b1e56bb77ac16f2ccf956fc24cf0a82L350 😛
Definitely open to name it something else, but I'll need to re-generate the certs 😅

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe malicious? I'm not sure what the intent is here.

@codecov-io
Copy link

codecov-io commented Mar 7, 2018

Codecov Report

Merging #924 into master will decrease coverage by 0.14%.
The diff coverage is 35.29%.

@@            Coverage Diff             @@
##           master     #924      +/-   ##
==========================================
- Coverage   53.92%   53.78%   -0.15%     
==========================================
  Files         262      262              
  Lines       16604    16601       -3     
==========================================
- Hits         8954     8929      -25     
- Misses       7049     7084      +35     
+ Partials      601      588      -13

Copy link
Contributor

@dnephin dnephin left a comment

Choose a reason for hiding this comment

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

This is a ton of work. Thanks for porting these!

ARG NOTARY_VERSION=v0.6.0
RUN export URL=https://github.com/theupdateframework/notary/releases/download; \
curl -Ls $URL/${NOTARY_VERSION}/notary-Linux-amd64 -o /usr/local/bin/notary && \
chmod +x /usr/local/bin/notary
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need this in the dev image? Aren't we using a docker image for the notary server?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For some tests (to come), we need to use the notary client to set up the server in some state.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add a TODO to move to a separate stage when we make this multi-stage? and document that it's only used from the e2e runner?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👍

@@ -17,5 +17,14 @@ services:
- notary-fixtures:/fixtures
command: ['notary-server', '-config=/fixtures/notary-config.json']

evil-notary-server:
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe malicious? I'm not sure what the intent is here.

)
result.Assert(t, icmd.Expected{
ExitCode: 1,
Err: "does not have trust data for",
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we test error cases with unit tests?

I guess this is running now, so maybe just add a TODO?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, and we probably should, that's a good point. I only worked moving from the moby's integration to cli's e2e tests but those could definitely be unit tests instead 👼 (with just one e2e tests that validates the behavior against a real server)

@@ -0,0 +1,78 @@
package image
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we keep this as pull_test.go ? We shouldn't have so many e2e tests that we need more than a single file per command.

})
}

func TestPullWithContentTrustUnreachableServer(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

TestPullWithContentTrustUsesCacheWhenNotaryUnavailable ?

"github.com/gotestyourself/gotestyourself/icmd"
)

func TestCreateWithContentTrust(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If both create and run use exactly the same code, do we need e2e tests for both?

Copy link
Contributor

Choose a reason for hiding this comment

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

I personally prefer too much tests than the opposite. Today they run the same code but we can catch an issue the day this is not true anymore (extremely unlikely I admit).

Err: "error contacting notary server",
})

// FIXME(vdemeester) doesn't work
Copy link
Contributor

Choose a reason for hiding this comment

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

ya, this is weird. I don't understand why it would hit notary if content trust is disabled.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep, but somehow, in moby, with 17.06, that's something it was doing 😅

@@ -0,0 +1,160 @@
package image
Copy link
Contributor

Choose a reason for hiding this comment

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

push_test.go ?


func TestPushWithContentTrustSignsForRolesWithKeysAndValidPaths(t *testing.T) {}

func TestPullWithContentTrustSignsForRolesWithKeysAndValidPaths(t *testing.T) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

There are way too many e2e tests here. It must be possible for some of these to be unit tests.


const registryPrefix = "registry:5000"

func TestPluginInstallWithContentTrust(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

TestInstallWithContentTrust


// FIXME(vdemeester) doesn't work
/*
// Now, try running with the original client from this new trust server. This should fail because the new root is invalid.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@endophage @n4ss what's the expected behavior here ? (the commented code comes from initial moby test suite, but fails on current docker/cli)

Err: "error contacting notary server",
})

// FIXME(vdemeester) doesn't work
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@endophage @n4ss what's the expected behavior here ? pretty sure it works as expected and the commented code should be gone, but somehow, in 17.06 it did act that way (i.e. even with --disable-content-trust it would fail)

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know.. If you disable content trust, it shouldn't try to reach the notary server, right?

@endophage @cyli if you have more guesses?

Copy link
Contributor

Choose a reason for hiding this comment

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

Apologies for not getting to this sooner - if it was this test: https://github.com/moby/moby/pull/36515/files#diff-cf31c649a9e77c869ff8c6cdcec05f60L328, it looks like the intention was to test the --disable-content-trust flag in combination with the content trust environment variable to say that even with the environment variable set, if --disable-content-trust is passed, it doesn't use content trust. So the push should work, because it doesn't contact the notary server, hence it seem to be checking that there is no comment about the notary server being invalid (e.g. if it were going the path of content trust, the push should have failed with that error message).

// FIXME(vdemeester) doesn't work
/*
// With a wrong password
result = icmd.RunCmd(icmd.Command("docker", "push", image),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@endophage @n4ss what's the expected behavior here ? (the commented code comes from initial moby test suite, but fails on current docker/cli)

Copy link
Contributor

Choose a reason for hiding this comment

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

Is that https://github.com/moby/moby/pull/36515/files#diff-cf31c649a9e77c869ff8c6cdcec05f60L368? If so, it's possible that the error message has changed - not sure what the failure on docker/cli was.

@vdemeester vdemeester force-pushed the trust-suite-tests branch 6 times, most recently from 931123c to 922cb69 Compare March 13, 2018 15:53
@vdemeester vdemeester changed the title [wip] Add some content trust tests Add some content trust tests Mar 13, 2018
Copy link
Contributor

@dnephin dnephin left a comment

Choose a reason for hiding this comment

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

LGTM when the commented code is removed (if it's not necessary anymore)

@vdemeester
Copy link
Collaborator Author

Updated with removing commented code (and cleaning some stuff not required for now)

@vdemeester
Copy link
Collaborator Author

The failure is weird 😱

17:18:22 --- FAIL: TestPushWithContentTrust (0.87s)
17:18:22 	push_test.go:43: assertion failed: 
17:18:22 		--- expected
17:18:22 		+++ actual
17:18:22 		@@ -1,6 +1,6 @@
17:18:22 		 The push refers to repository [registry:5000/trust-push]
17:18:22 		 5bef08742407: Preparing
17:18:22 		-5bef08742407: Mounted from trust-create
17:18:22 		+5bef08742407: Mounted from trust-pull-unreachable
17:18:22 		 latest: digest: sha256:641b95ddb2ea9dc2af1a0113b6b348ebc20872ba615204fbe12148e98fd6f23d size: 528
17:18:22 		 Signing and pushing trust metadata
17:18:22 		 Finished initializing "registry:5000/trust-push"

PS: I have another Mounted from on my laptop..

@vdemeester
Copy link
Collaborator Author

We either need to clean the registry between each test or.. something else 😓

@dnephin
Copy link
Contributor

dnephin commented Mar 14, 2018

We could use the line matching system from the image build test (https://github.com/docker/cli/blob/master/e2e/image/build_test.go#L31). Just needs to be renamed to assertLines or something like that.

@cyli
Copy link
Contributor

cyli commented Mar 14, 2018

Thank you so much for porting these @vdemeester! Apologies I didn't respond earlier. This all LGTM - I can attempt to add the TestTrustedPushWithoutServerAndUntrusted test back in another PR - that seems useful to test that the flag and the environment variable interact in the correct way, or perhaps that should just be a unit test.

TestTrustedPushWithIncorrectPassphraseForNonRoot possibly does not need to exist in docker/cli unless we translate the error messaging. I feel like this should be part of the notary tests instead. We have a test in notary for not being able to add data when the root passphrase is invalid (https://github.com/theupdateframework/notary/blob/master/client/client_test.go#L722) but not the repo passphrase. I've added an issue here: notaryproject/notary#1317

@vdemeester
Copy link
Collaborator Author

@dnephin updated, using assertBuildOuptut (move the thing in a separate package)

Copy link
Contributor

@dnephin dnephin left a comment

Choose a reason for hiding this comment

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

lint failure on unused code.


func TestServiceCreateWithContentTrust(t *testing.T) {}

func TestServiceUpdateWithContentTrust(t *testing.T) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

remove for now and open an issue for these?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

huh 😓

@vdemeester vdemeester force-pushed the trust-suite-tests branch 3 times, most recently from bd1b2a3 to ef5db75 Compare March 16, 2018 15:32
Importing from moby's DockerTrustSuite tests.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM

but left a comment 👍

@@ -23,3 +26,48 @@ func TestRunLabel(t *testing.T) {
cmd.SetArgs([]string{"--label", "foo", "busybox"})
assert.NilError(t, cmd.Execute())
}

func TestRunCommandWithContentTrustErrors(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

This is basically the same test as for "create" (TestNewCreateCommandWithContentTrustErrors); wonder (for a follow-up) if we can share some of the code, so that we don't have to maintain it twice, but also so that we make sure they're kept in sync

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants