-
-
Notifications
You must be signed in to change notification settings - Fork 474
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
Allow uid:gid to be specified during container creation #363
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,17 +5,19 @@ import ( | |
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"github.com/stretchr/testify/assert" | ||
"io/ioutil" | ||
"math/rand" | ||
"net/http" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"regexp" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/docker/docker/errdefs" | ||
|
||
"github.com/docker/docker/api/types/volume" | ||
|
@@ -1580,6 +1582,65 @@ func TestContainerWithReaperNetwork(t *testing.T) { | |
assert.NotNil(t, cnt.NetworkSettings.Networks[networks[1]]) | ||
} | ||
|
||
func TestContainerWithUserID(t *testing.T) { | ||
ctx := context.Background() | ||
req := ContainerRequest{ | ||
Image: "alpine:latest", | ||
User: "60125", | ||
Cmd: []string{"sh", "-c", "id -u"}, | ||
WaitingFor: wait.ForExit(), | ||
} | ||
container, err := GenericContainer(ctx, GenericContainerRequest{ | ||
ContainerRequest: req, | ||
Started: true, | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
Comment on lines
+1597
to
+1599
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: these if-statements can be replaced by calls to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True. I used There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you agree, would you mind sending the changes related to the require.NoError, or assert.Nil, in a follow up PR? |
||
defer container.Terminate(ctx) | ||
|
||
r, err := container.Logs(ctx) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer r.Close() | ||
b, err := ioutil.ReadAll(r) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
actual := regexp.MustCompile(`\D+`).ReplaceAllString(string(b), "") | ||
assert.Equal(t, req.User, actual) | ||
} | ||
|
||
func TestContainerWithNoUserID(t *testing.T) { | ||
ctx := context.Background() | ||
req := ContainerRequest{ | ||
Image: "alpine:latest", | ||
Cmd: []string{"sh", "-c", "id -u"}, | ||
WaitingFor: wait.ForExit(), | ||
} | ||
container, err := GenericContainer(ctx, GenericContainerRequest{ | ||
ContainerRequest: req, | ||
Started: true, | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer container.Terminate(ctx) | ||
|
||
r, err := container.Logs(ctx) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer r.Close() | ||
b, err := ioutil.ReadAll(r) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
actual := regexp.MustCompile(`\D+`).ReplaceAllString(string(b), "") | ||
assert.Equal(t, "0", actual) | ||
} | ||
|
||
func TestGetGatewayIP(t *testing.T) { | ||
// When using docker-compose with DinD mode, and using host port or http wait strategy | ||
// It's need to invoke GetGatewayIP for get the host | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would happen if the
req.User
is empty? Will the docker client understand that asroot
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
User
is a string field, so it appears that an empty string equates to not setting a UID at all:Confirmed with these tests:
Output:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind adding two tests in your PR: one for adding the User, and another one without it?
Besides that, we could only set the
User
field ifreq.User
is not emptyThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mdelapenya sure thing! Tests have been added.