|
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; |
19 | 21 |
|
20 | 22 | import static org.hamcrest.MatcherAssert.assertThat;
|
21 | 23 | import static org.hamcrest.Matchers.containsString;
|
@@ -158,10 +160,11 @@ public void copyFileWithUIDGID() throws Exception {
|
158 | 160 | Path without = Files.createFile(Files.createTempDirectory("copyFileWithUIDGID").resolve("uidgid.without"));
|
159 | 161 | Files.write(without, "with".getBytes());
|
160 | 162 |
|
161 |
| - String containerCmd = "while [ ! -f /home/uidgid.with ]; do true; done && stat -c %n:%u /home/uidgid.with /home/uidgid.without"; |
| 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"; |
162 | 164 | CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox")
|
163 | 165 | .withName("copyFileWithUIDGID")
|
164 | 166 | .withCmd("/bin/sh", "-c", containerCmd)
|
| 167 | + .withUser("sync") |
165 | 168 | .exec();
|
166 | 169 | // start the container
|
167 | 170 | dockerRule.getClient().startContainerCmd(container.getId()).exec();
|
@@ -192,11 +195,18 @@ public void copyFileWithUIDGID() throws Exception {
|
192 | 195 | .exec(loggingCallback);
|
193 | 196 |
|
194 | 197 | loggingCallback.awaitCompletion(3, TimeUnit.SECONDS);
|
195 |
| - assertThat(loggingCallback.toString(), containsString("/home/uidgid.with:0")); |
| 198 | + String containerOutput = loggingCallback.toString(); |
| 199 | + |
| 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))); |
196 | 206 |
|
197 | 207 | Long hostUid = getHostUidIfPossible();
|
198 | 208 | assumeThat("could not get the uid on host platform", hostUid, notNullValue(Long.class));
|
199 |
| - assertThat(loggingCallback.toString(), containsString(String.format("/home/uidgid.without:%d", hostUid))); |
| 209 | + assertThat(containerOutput, containsString(String.format("/home/uidgid.without:%d", hostUid))); |
200 | 210 | }
|
201 | 211 |
|
202 | 212 | private static Long getHostUidIfPossible() {
|
|
0 commit comments