2014-05-09 10:32:19 +00:00
package main
import (
"encoding/json"
2015-05-22 23:15:14 +00:00
"fmt"
2014-11-11 16:17:33 +00:00
"os"
2015-01-07 00:04:10 +00:00
"reflect"
2015-04-06 13:21:18 +00:00
"strings"
2014-05-09 10:32:19 +00:00
"time"
2015-02-26 04:16:44 +00:00
2015-07-22 18:39:35 +00:00
"os/exec"
2015-07-23 01:46:59 +00:00
"io/ioutil"
2015-11-03 04:24:12 +00:00
"github.com/docker/docker/pkg/integration/checker"
2015-11-18 22:20:54 +00:00
"github.com/docker/docker/pkg/stringid"
2015-12-18 17:58:48 +00:00
"github.com/docker/go-connections/nat"
2015-04-18 16:46:47 +00:00
"github.com/go-check/check"
2014-05-09 10:32:19 +00:00
)
// Make sure we can create a simple container with some args
2015-04-18 16:46:47 +00:00
func ( s * DockerSuite ) TestCreateArgs ( c * check . C ) {
2016-02-03 00:00:39 +00:00
// TODO Windows. This requires further investigation for porting to
// Windows CI. Currently fails.
if daemonPlatform == "windows" {
c . Skip ( "Fails on Windows CI" )
}
2015-07-14 06:35:36 +00:00
out , _ := dockerCmd ( c , "create" , "busybox" , "command" , "arg1" , "arg2" , "arg with space" )
2014-05-09 10:32:19 +00:00
2015-04-06 13:21:18 +00:00
cleanedContainerID := strings . TrimSpace ( out )
2014-05-09 10:32:19 +00:00
2015-07-14 06:35:36 +00:00
out , _ = dockerCmd ( c , "inspect" , cleanedContainerID )
2014-05-09 10:32:19 +00:00
containers := [ ] struct {
ID string
Created time . Time
Path string
Args [ ] string
Image string
} { }
2015-11-03 04:24:12 +00:00
err := json . Unmarshal ( [ ] byte ( out ) , & containers )
c . Assert ( err , check . IsNil , check . Commentf ( "Error inspecting the container: %s" , err ) )
c . Assert ( containers , checker . HasLen , 1 )
2014-05-09 10:32:19 +00:00
2015-04-18 16:46:47 +00:00
cont := containers [ 0 ]
2015-11-03 04:24:12 +00:00
c . Assert ( string ( cont . Path ) , checker . Equals , "command" , check . Commentf ( "Unexpected container path. Expected command, received: %s" , cont . Path ) )
2014-05-09 10:32:19 +00:00
b := false
expected := [ ] string { "arg1" , "arg2" , "arg with space" }
for i , arg := range expected {
2015-04-18 16:46:47 +00:00
if arg != cont . Args [ i ] {
2014-05-09 10:32:19 +00:00
b = true
break
}
}
2015-04-18 16:46:47 +00:00
if len ( cont . Args ) != len ( expected ) || b {
c . Fatalf ( "Unexpected args. Expected %v, received: %v" , expected , cont . Args )
2014-05-09 10:32:19 +00:00
}
}
// Make sure we can set hostconfig options too
2015-04-18 16:46:47 +00:00
func ( s * DockerSuite ) TestCreateHostConfig ( c * check . C ) {
2015-07-14 06:35:36 +00:00
out , _ := dockerCmd ( c , "create" , "-P" , "busybox" , "echo" )
2014-05-09 10:32:19 +00:00
2015-04-06 13:21:18 +00:00
cleanedContainerID := strings . TrimSpace ( out )
2014-05-09 10:32:19 +00:00
2015-07-14 06:35:36 +00:00
out , _ = dockerCmd ( c , "inspect" , cleanedContainerID )
2014-05-09 10:32:19 +00:00
containers := [ ] struct {
HostConfig * struct {
PublishAllPorts bool
}
} { }
2015-11-03 04:24:12 +00:00
err := json . Unmarshal ( [ ] byte ( out ) , & containers )
c . Assert ( err , check . IsNil , check . Commentf ( "Error inspecting the container: %s" , err ) )
c . Assert ( containers , checker . HasLen , 1 )
2014-05-09 10:32:19 +00:00
2015-11-03 04:24:12 +00:00
cont := containers [ 0 ]
c . Assert ( cont . HostConfig , check . NotNil , check . Commentf ( "Expected HostConfig, got none" ) )
c . Assert ( cont . HostConfig . PublishAllPorts , check . NotNil , check . Commentf ( "Expected PublishAllPorts, got false" ) )
2014-05-09 10:32:19 +00:00
}
2015-04-18 16:46:47 +00:00
func ( s * DockerSuite ) TestCreateWithPortRange ( c * check . C ) {
2016-02-03 00:00:39 +00:00
// Windows does not currently support port ranges.
2015-08-28 17:36:42 +00:00
testRequires ( c , DaemonIsLinux )
2015-07-14 06:35:36 +00:00
out , _ := dockerCmd ( c , "create" , "-p" , "3300-3303:3300-3303/tcp" , "busybox" , "echo" )
2014-11-03 18:15:55 +00:00
2015-04-06 13:21:18 +00:00
cleanedContainerID := strings . TrimSpace ( out )
2014-11-03 18:15:55 +00:00
2015-07-14 06:35:36 +00:00
out , _ = dockerCmd ( c , "inspect" , cleanedContainerID )
2014-11-03 18:15:55 +00:00
containers := [ ] struct {
HostConfig * struct {
PortBindings map [ nat . Port ] [ ] nat . PortBinding
}
} { }
2015-11-03 04:24:12 +00:00
err := json . Unmarshal ( [ ] byte ( out ) , & containers )
c . Assert ( err , check . IsNil , check . Commentf ( "Error inspecting the container: %s" , err ) )
c . Assert ( containers , checker . HasLen , 1 )
2014-11-03 18:15:55 +00:00
2015-04-18 16:46:47 +00:00
cont := containers [ 0 ]
2014-11-03 18:15:55 +00:00
2015-11-03 04:24:12 +00:00
c . Assert ( cont . HostConfig , check . NotNil , check . Commentf ( "Expected HostConfig, got none" ) )
c . Assert ( cont . HostConfig . PortBindings , checker . HasLen , 4 , check . Commentf ( "Expected 4 ports bindings, got %d" , len ( cont . HostConfig . PortBindings ) ) )
2015-04-18 16:46:47 +00:00
for k , v := range cont . HostConfig . PortBindings {
2015-11-03 04:24:12 +00:00
c . Assert ( v , checker . HasLen , 1 , check . Commentf ( "Expected 1 ports binding, for the port %s but found %s" , k , v ) )
c . Assert ( k . Port ( ) , checker . Equals , v [ 0 ] . HostPort , check . Commentf ( "Expected host port %s to match published port %s" , k . Port ( ) , v [ 0 ] . HostPort ) )
2014-11-03 18:15:55 +00:00
}
}
2016-02-03 00:00:39 +00:00
func ( s * DockerSuite ) TestCreateWithLargePortRange ( c * check . C ) {
// Windows does not currently support port ranges.
2015-08-28 17:36:42 +00:00
testRequires ( c , DaemonIsLinux )
2015-07-14 06:35:36 +00:00
out , _ := dockerCmd ( c , "create" , "-p" , "1-65535:1-65535/tcp" , "busybox" , "echo" )
2014-11-03 18:15:55 +00:00
2015-04-06 13:21:18 +00:00
cleanedContainerID := strings . TrimSpace ( out )
2014-11-03 18:15:55 +00:00
2015-07-14 06:35:36 +00:00
out , _ = dockerCmd ( c , "inspect" , cleanedContainerID )
2014-11-03 18:15:55 +00:00
containers := [ ] struct {
HostConfig * struct {
PortBindings map [ nat . Port ] [ ] nat . PortBinding
}
} { }
2015-11-03 04:24:12 +00:00
err := json . Unmarshal ( [ ] byte ( out ) , & containers )
c . Assert ( err , check . IsNil , check . Commentf ( "Error inspecting the container: %s" , err ) )
c . Assert ( containers , checker . HasLen , 1 )
2014-11-03 18:15:55 +00:00
2015-04-18 16:46:47 +00:00
cont := containers [ 0 ]
2015-11-03 04:24:12 +00:00
c . Assert ( cont . HostConfig , check . NotNil , check . Commentf ( "Expected HostConfig, got none" ) )
c . Assert ( cont . HostConfig . PortBindings , checker . HasLen , 65535 )
2014-11-03 18:15:55 +00:00
2015-04-18 16:46:47 +00:00
for k , v := range cont . HostConfig . PortBindings {
2015-11-03 04:24:12 +00:00
c . Assert ( v , checker . HasLen , 1 )
c . Assert ( k . Port ( ) , checker . Equals , v [ 0 ] . HostPort , check . Commentf ( "Expected host port %s to match published port %s" , k . Port ( ) , v [ 0 ] . HostPort ) )
2014-11-03 18:15:55 +00:00
}
}
2014-05-09 10:32:19 +00:00
// "test123" should be printed by docker create + start
2015-04-18 16:46:47 +00:00
func ( s * DockerSuite ) TestCreateEchoStdout ( c * check . C ) {
2015-07-14 06:35:36 +00:00
out , _ := dockerCmd ( c , "create" , "busybox" , "echo" , "test123" )
2014-05-09 10:32:19 +00:00
2015-04-06 13:21:18 +00:00
cleanedContainerID := strings . TrimSpace ( out )
2014-05-09 10:32:19 +00:00
2015-07-14 06:35:36 +00:00
out , _ = dockerCmd ( c , "start" , "-ai" , cleanedContainerID )
2015-11-03 04:24:12 +00:00
c . Assert ( out , checker . Equals , "test123\n" , check . Commentf ( "container should've printed 'test123', got %q" , out ) )
2014-05-09 10:32:19 +00:00
}
2014-11-11 16:17:33 +00:00
2015-04-18 16:46:47 +00:00
func ( s * DockerSuite ) TestCreateVolumesCreated ( c * check . C ) {
testRequires ( c , SameHostDaemon )
2016-02-03 00:00:39 +00:00
prefix := "/"
if daemonPlatform == "windows" {
prefix = ` c:\ `
}
2015-02-20 06:56:02 +00:00
2014-11-11 16:17:33 +00:00
name := "test_create_volume"
2016-02-03 00:00:39 +00:00
dockerCmd ( c , "create" , "--name" , name , "-v" , prefix + "foo" , "busybox" )
2015-07-14 06:35:36 +00:00
2016-02-03 00:00:39 +00:00
dir , err := inspectMountSourceField ( name , prefix + "foo" )
2015-11-03 04:24:12 +00:00
c . Assert ( err , check . IsNil , check . Commentf ( "Error getting volume host path: %q" , err ) )
2014-11-11 16:17:33 +00:00
if _ , err := os . Stat ( dir ) ; err != nil && os . IsNotExist ( err ) {
2015-04-18 16:46:47 +00:00
c . Fatalf ( "Volume was not created" )
2014-11-11 16:17:33 +00:00
}
if err != nil {
2015-04-18 16:46:47 +00:00
c . Fatalf ( "Error statting volume host path: %q" , err )
2014-11-11 16:17:33 +00:00
}
}
2015-01-07 00:04:10 +00:00
2015-04-18 16:46:47 +00:00
func ( s * DockerSuite ) TestCreateLabels ( c * check . C ) {
2015-01-07 00:04:10 +00:00
name := "test_create_labels"
expected := map [ string ] string { "k1" : "v1" , "k2" : "v2" }
2015-07-14 06:35:36 +00:00
dockerCmd ( c , "create" , "--name" , name , "-l" , "k1=v1" , "--label" , "k2=v2" , "busybox" )
2015-01-07 00:04:10 +00:00
actual := make ( map [ string ] string )
2016-01-28 14:19:25 +00:00
inspectFieldAndMarshall ( c , name , "Config.Labels" , & actual )
2015-01-07 00:04:10 +00:00
if ! reflect . DeepEqual ( expected , actual ) {
2015-04-18 16:46:47 +00:00
c . Fatalf ( "Expected %s got %s" , expected , actual )
2015-01-07 00:04:10 +00:00
}
}
2015-04-18 16:46:47 +00:00
func ( s * DockerSuite ) TestCreateLabelFromImage ( c * check . C ) {
2015-01-07 00:04:10 +00:00
imageName := "testcreatebuildlabel"
_ , err := buildImage ( imageName ,
` FROM busybox
LABEL k1 = v1 k2 = v2 ` ,
true )
2015-11-03 04:24:12 +00:00
c . Assert ( err , check . IsNil )
2015-01-07 00:04:10 +00:00
name := "test_create_labels_from_image"
2015-08-11 23:48:41 +00:00
expected := map [ string ] string { "k2" : "x" , "k3" : "v3" , "k1" : "v1" }
2015-07-14 06:35:36 +00:00
dockerCmd ( c , "create" , "--name" , name , "-l" , "k2=x" , "--label" , "k3=v3" , imageName )
2015-01-07 00:04:10 +00:00
actual := make ( map [ string ] string )
2016-01-28 14:19:25 +00:00
inspectFieldAndMarshall ( c , name , "Config.Labels" , & actual )
2015-01-07 00:04:10 +00:00
if ! reflect . DeepEqual ( expected , actual ) {
2015-04-18 16:46:47 +00:00
c . Fatalf ( "Expected %s got %s" , expected , actual )
2015-01-07 00:04:10 +00:00
}
}
2015-04-10 21:06:43 +00:00
2015-04-18 16:46:47 +00:00
func ( s * DockerSuite ) TestCreateHostnameWithNumber ( c * check . C ) {
2016-02-03 00:00:39 +00:00
// TODO Windows. Consider enabling this in TP5 timeframe if Windows support
// is fully hooked up. The hostname is passed through, but only to the
// environment variable "COMPUTERNAME". It is not hooked up to hostname.exe
// or returned in ipconfig. Needs platform support in networking.
2015-08-28 17:36:42 +00:00
testRequires ( c , DaemonIsLinux )
2015-04-18 16:46:47 +00:00
out , _ := dockerCmd ( c , "run" , "-h" , "web.0" , "busybox" , "hostname" )
2015-11-03 04:24:12 +00:00
c . Assert ( strings . TrimSpace ( out ) , checker . Equals , "web.0" , check . Commentf ( "hostname not set, expected `web.0`, got: %s" , out ) )
2015-04-10 21:06:43 +00:00
}
2015-05-21 14:30:51 +00:00
func ( s * DockerSuite ) TestCreateRM ( c * check . C ) {
// Test to make sure we can 'rm' a new container that is in
// "Created" state, and has ever been run. Test "rm -f" too.
// create a container
2015-07-14 06:35:36 +00:00
out , _ := dockerCmd ( c , "create" , "busybox" )
2015-05-21 14:30:51 +00:00
cID := strings . TrimSpace ( out )
2015-07-14 06:35:36 +00:00
dockerCmd ( c , "rm" , cID )
2015-05-21 14:30:51 +00:00
// Now do it again so we can "rm -f" this time
2015-07-14 06:35:36 +00:00
out , _ = dockerCmd ( c , "create" , "busybox" )
2015-05-21 14:30:51 +00:00
cID = strings . TrimSpace ( out )
2015-07-14 06:35:36 +00:00
dockerCmd ( c , "rm" , "-f" , cID )
2015-05-21 14:30:51 +00:00
}
2015-05-22 23:15:14 +00:00
func ( s * DockerSuite ) TestCreateModeIpcContainer ( c * check . C ) {
2016-02-03 00:00:39 +00:00
// Uses Linux specific functionality (--ipc)
2016-03-23 13:37:15 +00:00
testRequires ( c , DaemonIsLinux , SameHostDaemon )
2015-05-22 23:15:14 +00:00
2015-07-14 06:35:36 +00:00
out , _ := dockerCmd ( c , "create" , "busybox" )
2015-05-22 23:15:14 +00:00
id := strings . TrimSpace ( out )
2015-07-14 06:35:36 +00:00
dockerCmd ( c , "create" , fmt . Sprintf ( "--ipc=container:%s" , id ) , "busybox" )
2015-05-22 23:15:14 +00:00
}
2015-07-22 16:14:48 +00:00
2015-11-18 22:20:54 +00:00
func ( s * DockerSuite ) TestCreateByImageID ( c * check . C ) {
imageName := "testcreatebyimageid"
imageID , err := buildImage ( imageName ,
` FROM busybox
MAINTAINER dockerio ` ,
true )
if err != nil {
c . Fatal ( err )
}
truncatedImageID := stringid . TruncateID ( imageID )
dockerCmd ( c , "create" , imageID )
dockerCmd ( c , "create" , truncatedImageID )
dockerCmd ( c , "create" , fmt . Sprintf ( "%s:%s" , imageName , truncatedImageID ) )
// Ensure this fails
out , exit , _ := dockerCmdWithError ( "create" , fmt . Sprintf ( "%s:%s" , imageName , imageID ) )
if exit == 0 {
c . Fatalf ( "expected non-zero exit code; received %d" , exit )
}
2015-12-10 07:31:38 +00:00
if expected := "Error parsing reference" ; ! strings . Contains ( out , expected ) {
2015-11-18 22:20:54 +00:00
c . Fatalf ( ` Expected %q in output; got: %s ` , expected , out )
}
out , exit , _ = dockerCmdWithError ( "create" , fmt . Sprintf ( "%s:%s" , "wrongimage" , truncatedImageID ) )
if exit == 0 {
c . Fatalf ( "expected non-zero exit code; received %d" , exit )
}
if expected := "Unable to find image" ; ! strings . Contains ( out , expected ) {
c . Fatalf ( ` Expected %q in output; got: %s ` , expected , out )
}
}
2015-07-22 16:14:48 +00:00
func ( s * DockerTrustSuite ) TestTrustedCreate ( c * check . C ) {
2015-07-23 12:12:36 +00:00
repoName := s . setupTrustedImage ( c , "trusted-create" )
2015-07-22 16:14:48 +00:00
// Try create
createCmd := exec . Command ( dockerBinary , "create" , repoName )
s . trustedCmd ( createCmd )
2015-07-23 12:12:36 +00:00
out , _ , err := runCommandWithOutput ( createCmd )
2015-11-03 04:24:12 +00:00
c . Assert ( err , check . IsNil )
c . Assert ( string ( out ) , checker . Contains , "Tagging" , check . Commentf ( "Missing expected output on trusted push:\n%s" , out ) )
2015-07-22 16:14:48 +00:00
dockerCmd ( c , "rmi" , repoName )
// Try untrusted create to ensure we pushed the tag to the registry
2015-07-24 08:59:42 +00:00
createCmd = exec . Command ( dockerBinary , "create" , "--disable-content-trust=true" , repoName )
2015-07-22 16:14:48 +00:00
s . trustedCmd ( createCmd )
out , _ , err = runCommandWithOutput ( createCmd )
2015-11-03 04:24:12 +00:00
c . Assert ( err , check . IsNil )
c . Assert ( string ( out ) , checker . Contains , "Status: Downloaded" , check . Commentf ( "Missing expected output on trusted create with --disable-content-trust:\n%s" , out ) )
2015-07-22 16:14:48 +00:00
}
func ( s * DockerTrustSuite ) TestUntrustedCreate ( c * check . C ) {
2016-01-27 01:52:36 +00:00
repoName := fmt . Sprintf ( "%v/dockercliuntrusted/createtest" , privateRegistryURL )
withTagName := fmt . Sprintf ( "%s:latest" , repoName )
2015-07-22 16:14:48 +00:00
// tag the image and upload it to the private registry
2016-01-27 01:52:36 +00:00
dockerCmd ( c , "tag" , "busybox" , withTagName )
dockerCmd ( c , "push" , withTagName )
dockerCmd ( c , "rmi" , withTagName )
2015-07-22 16:14:48 +00:00
// Try trusted create on untrusted tag
2016-01-27 01:52:36 +00:00
createCmd := exec . Command ( dockerBinary , "create" , withTagName )
2015-07-22 16:14:48 +00:00
s . trustedCmd ( createCmd )
out , _ , err := runCommandWithOutput ( createCmd )
2015-11-03 04:24:12 +00:00
c . Assert ( err , check . Not ( check . IsNil ) )
2016-01-27 01:52:36 +00:00
c . Assert ( string ( out ) , checker . Contains , fmt . Sprintf ( "does not have trust data for %s" , repoName ) , check . Commentf ( "Missing expected output on trusted create:\n%s" , out ) )
2015-07-22 16:14:48 +00:00
}
2015-07-23 12:12:36 +00:00
func ( s * DockerTrustSuite ) TestTrustedIsolatedCreate ( c * check . C ) {
repoName := s . setupTrustedImage ( c , "trusted-isolated-create" )
2015-07-22 16:14:48 +00:00
2015-07-23 12:12:36 +00:00
// Try create
createCmd := exec . Command ( dockerBinary , "--config" , "/tmp/docker-isolated-create" , "create" , repoName )
s . trustedCmd ( createCmd )
out , _ , err := runCommandWithOutput ( createCmd )
2015-11-03 04:24:12 +00:00
c . Assert ( err , check . IsNil )
c . Assert ( string ( out ) , checker . Contains , "Tagging" , check . Commentf ( "Missing expected output on trusted push:\n%s" , out ) )
2015-07-22 16:14:48 +00:00
dockerCmd ( c , "rmi" , repoName )
2015-07-23 12:12:36 +00:00
}
func ( s * DockerTrustSuite ) TestCreateWhenCertExpired ( c * check . C ) {
2015-07-29 19:09:40 +00:00
c . Skip ( "Currently changes system time, causing instability" )
2015-07-23 12:12:36 +00:00
repoName := s . setupTrustedImage ( c , "trusted-create-expired" )
2015-07-22 16:14:48 +00:00
// Certificates have 10 years of expiration
elevenYearsFromNow := time . Now ( ) . Add ( time . Hour * 24 * 365 * 11 )
runAtDifferentDate ( elevenYearsFromNow , func ( ) {
// Try create
createCmd := exec . Command ( dockerBinary , "create" , repoName )
s . trustedCmd ( createCmd )
2015-07-23 12:12:36 +00:00
out , _ , err := runCommandWithOutput ( createCmd )
2015-11-03 04:24:12 +00:00
c . Assert ( err , check . Not ( check . IsNil ) )
c . Assert ( string ( out ) , checker . Contains , "could not validate the path to a trusted root" , check . Commentf ( "Missing expected output on trusted create in the distant future:\n%s" , out ) )
2015-07-22 16:14:48 +00:00
} )
runAtDifferentDate ( elevenYearsFromNow , func ( ) {
// Try create
2015-07-24 08:59:42 +00:00
createCmd := exec . Command ( dockerBinary , "create" , "--disable-content-trust" , repoName )
2015-07-22 16:14:48 +00:00
s . trustedCmd ( createCmd )
2015-07-23 12:12:36 +00:00
out , _ , err := runCommandWithOutput ( createCmd )
2015-11-03 04:24:12 +00:00
c . Assert ( err , check . Not ( check . IsNil ) )
c . Assert ( string ( out ) , checker . Contains , "Status: Downloaded" , check . Commentf ( "Missing expected output on trusted create in the distant future:\n%s" , out ) )
2015-07-22 16:14:48 +00:00
} )
}
2015-07-22 23:10:25 +00:00
func ( s * DockerTrustSuite ) TestTrustedCreateFromBadTrustServer ( c * check . C ) {
repoName := fmt . Sprintf ( "%v/dockerclievilcreate/trusted:latest" , privateRegistryURL )
2016-02-25 21:40:00 +00:00
evilLocalConfigDir , err := ioutil . TempDir ( "" , "evilcreate-local-config-dir" )
2015-11-03 04:24:12 +00:00
c . Assert ( err , check . IsNil )
2015-07-22 23:10:25 +00:00
// tag the image and upload it to the private registry
dockerCmd ( c , "tag" , "busybox" , repoName )
pushCmd := exec . Command ( dockerBinary , "push" , repoName )
s . trustedCmd ( pushCmd )
out , _ , err := runCommandWithOutput ( pushCmd )
2015-11-03 04:24:12 +00:00
c . Assert ( err , check . IsNil )
c . Assert ( string ( out ) , checker . Contains , "Signing and pushing trust metadata" , check . Commentf ( "Missing expected output on trusted push:\n%s" , out ) )
2015-07-22 23:10:25 +00:00
dockerCmd ( c , "rmi" , repoName )
// Try create
createCmd := exec . Command ( dockerBinary , "create" , repoName )
s . trustedCmd ( createCmd )
out , _ , err = runCommandWithOutput ( createCmd )
2015-11-03 04:24:12 +00:00
c . Assert ( err , check . IsNil )
c . Assert ( string ( out ) , checker . Contains , "Tagging" , check . Commentf ( "Missing expected output on trusted push:\n%s" , out ) )
2015-07-22 23:10:25 +00:00
dockerCmd ( c , "rmi" , repoName )
// Kill the notary server, start a new "evil" one.
s . not . Close ( )
s . not , err = newTestNotary ( c )
2015-11-03 04:24:12 +00:00
c . Assert ( err , check . IsNil )
2015-07-22 23:10:25 +00:00
// In order to make an evil server, lets re-init a client (with a different trust dir) and push new data.
// tag an image and upload it to the private registry
dockerCmd ( c , "--config" , evilLocalConfigDir , "tag" , "busybox" , repoName )
// Push up to the new server
pushCmd = exec . Command ( dockerBinary , "--config" , evilLocalConfigDir , "push" , repoName )
s . trustedCmd ( pushCmd )
out , _ , err = runCommandWithOutput ( pushCmd )
2015-11-03 04:24:12 +00:00
c . Assert ( err , check . IsNil )
c . Assert ( string ( out ) , checker . Contains , "Signing and pushing trust metadata" , check . Commentf ( "Missing expected output on trusted push:\n%s" , out ) )
2015-07-22 23:10:25 +00:00
2016-02-25 21:40:00 +00:00
// Now, try creating with the original client from this new trust server. This should fallback to our cached timestamp and metadata.
2015-07-22 23:10:25 +00:00
createCmd = exec . Command ( dockerBinary , "create" , repoName )
s . trustedCmd ( createCmd )
out , _ , err = runCommandWithOutput ( createCmd )
2016-02-25 21:40:00 +00:00
if err != nil {
c . Fatalf ( "Error falling back to cached trust data: %s\n%s" , err , out )
}
if ! strings . Contains ( string ( out ) , "Error while downloading remote metadata, using cached timestamp" ) {
c . Fatalf ( "Missing expected output on trusted create:\n%s" , out )
}
2015-07-22 23:10:25 +00:00
}
2015-08-18 17:30:44 +00:00
func ( s * DockerSuite ) TestCreateStopSignal ( c * check . C ) {
name := "test_create_stop_signal"
dockerCmd ( c , "create" , "--name" , name , "--stop-signal" , "9" , "busybox" )
2016-01-28 14:19:25 +00:00
res := inspectFieldJSON ( c , name , "Config.StopSignal" )
2015-11-03 04:24:12 +00:00
c . Assert ( res , checker . Contains , "9" )
2015-08-18 17:30:44 +00:00
}
2016-01-08 04:11:21 +00:00
func ( s * DockerSuite ) TestCreateWithWorkdir ( c * check . C ) {
2016-02-03 00:00:39 +00:00
// TODO Windows. This requires further investigation for porting to
// Windows CI. Currently fails.
if daemonPlatform == "windows" {
c . Skip ( "Fails on Windows CI" )
}
2016-01-08 04:11:21 +00:00
name := "foo"
2016-02-03 14:16:00 +00:00
prefix , slash := getPrefixAndSlashFromDaemonPlatform ( )
2016-02-03 00:00:39 +00:00
dir := prefix + slash + "home" + slash + "foo" + slash + "bar"
2016-01-08 04:11:21 +00:00
dockerCmd ( c , "create" , "--name" , name , "-w" , dir , "busybox" )
2016-02-03 00:00:39 +00:00
dockerCmd ( c , "cp" , fmt . Sprintf ( "%s:%s" , name , dir ) , prefix + slash + "tmp" )
2016-01-08 04:11:21 +00:00
}
2016-02-27 17:38:26 +00:00
func ( s * DockerSuite ) TestCreateWithInvalidLogOpts ( c * check . C ) {
name := "test-invalidate-log-opts"
2016-03-02 12:22:18 +00:00
out , _ , err := dockerCmdWithError ( "create" , "--name" , name , "--log-opt" , "invalid=true" , "busybox" )
2016-02-27 17:38:26 +00:00
c . Assert ( err , checker . NotNil )
2016-03-02 12:22:18 +00:00
c . Assert ( out , checker . Contains , "unknown log opt" )
out , _ = dockerCmd ( c , "ps" , "-a" )
2016-02-27 17:38:26 +00:00
c . Assert ( out , checker . Not ( checker . Contains ) , name )
}
2016-03-07 18:56:24 +00:00
// #20972
func ( s * DockerSuite ) TestCreate64ByteHexID ( c * check . C ) {
out := inspectField ( c , "busybox" , "Id" )
imageID := strings . TrimPrefix ( strings . TrimSpace ( string ( out ) ) , "sha256:" )
dockerCmd ( c , "create" , imageID )
}