|
16 | 16 | import java.nio.file.Path; |
17 | 17 | import java.nio.file.Paths; |
18 | 18 | import java.util.concurrent.TimeUnit; |
19 | | -import java.util.regex.Matcher; |
20 | | -import java.util.regex.Pattern; |
21 | 19 |
|
22 | 20 | import static org.hamcrest.MatcherAssert.assertThat; |
23 | 21 | import static org.hamcrest.Matchers.containsString; |
@@ -160,11 +158,12 @@ public void copyFileWithUIDGID() throws Exception { |
160 | 158 | Path without = Files.createFile(Files.createTempDirectory("copyFileWithUIDGID").resolve("uidgid.without")); |
161 | 159 | Files.write(without, "with".getBytes()); |
162 | 160 |
|
163 | | - String containerCmd = "while [ ! -f /home/uidgid.with ]; do true; done && echo uid=$(id -u) && stat -c %n:%u /home/uidgid.with /home/uidgid.without"; |
| 161 | + String containerCmd = "while [ ! -f /home/uidgid.with ]; do true; done && stat -c %n:%u /home/uidgid.with /home/uidgid.without"; |
| 162 | + Long syncUserUid = 4L; // sync user in busybox was uid=4 |
164 | 163 | CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox") |
165 | 164 | .withName("copyFileWithUIDGID") |
166 | 165 | .withCmd("/bin/sh", "-c", containerCmd) |
167 | | - .withUser("sync") |
| 166 | + .withUser(syncUserUid.toString()) |
168 | 167 | .exec(); |
169 | 168 | // start the container |
170 | 169 | dockerRule.getClient().startContainerCmd(container.getId()).exec(); |
@@ -197,12 +196,7 @@ public void copyFileWithUIDGID() throws Exception { |
197 | 196 | loggingCallback.awaitCompletion(3, TimeUnit.SECONDS); |
198 | 197 | String containerOutput = loggingCallback.toString(); |
199 | 198 |
|
200 | | - Matcher uidMatcher = Pattern.compile("uid=(\\d+)").matcher(containerOutput); |
201 | | - assertThat(String.format("cannot read effective uid on container from '%s'", containerOutput), uidMatcher.find(), equalTo(true)); |
202 | | - assertThat(String.format("cannot read effective uid on container from '%s'", containerOutput), uidMatcher.groupCount(), equalTo(1)); |
203 | | - Long containerEffectiveUid = Long.parseLong(uidMatcher.group(1)); |
204 | | - |
205 | | - assertThat(containerOutput, containsString(String.format("/home/uidgid.with:%d", containerEffectiveUid))); |
| 199 | + assertThat(containerOutput, containsString(String.format("/home/uidgid.with:%d", syncUserUid))); |
206 | 200 |
|
207 | 201 | Long hostUid = getHostUidIfPossible(); |
208 | 202 | assumeThat("could not get the uid on host platform", hostUid, notNullValue(Long.class)); |
|
0 commit comments