diff --git a/docker-java-api/src/main/java/com/github/dockerjava/api/model/Bind.java b/docker-java-api/src/main/java/com/github/dockerjava/api/model/Bind.java index c9aecf9d4..f82e5d482 100644 --- a/docker-java-api/src/main/java/com/github/dockerjava/api/model/Bind.java +++ b/docker-java-api/src/main/java/com/github/dockerjava/api/model/Bind.java @@ -97,7 +97,8 @@ public PropagationMode getPropagationMode() { */ public static Bind parse(String serialized) { try { - String[] parts = serialized.split(":"); + // Split by ':' but not ':\' (Windows-style path) + String[] parts = serialized.split(":(?!\\\\)"); switch (parts.length) { case 2: { return new Bind(parts[0], new Volume(parts[1])); diff --git a/docker-java/src/test/java/com/github/dockerjava/api/model/BindTest.java b/docker-java/src/test/java/com/github/dockerjava/api/model/BindTest.java index 3343bf6bd..663231151 100644 --- a/docker-java/src/test/java/com/github/dockerjava/api/model/BindTest.java +++ b/docker-java/src/test/java/com/github/dockerjava/api/model/BindTest.java @@ -26,6 +26,113 @@ public void parseUsingDefaultAccessMode() { assertThat(bind.getPropagationMode(), is(PropagationMode.DEFAULT_MODE)); } + @Test + public void parseReadWriteWindows() { + Bind bind = Bind.parse("C:\\host:/container:rw"); + assertThat(bind.getPath(), is("C:\\host")); + assertThat(bind.getVolume().getPath(), is("/container")); + assertThat(bind.getAccessMode(), is(rw)); + assertThat(bind.getSecMode(), is(SELContext.none)); + assertThat(bind.getNoCopy(), nullValue()); + assertThat(bind.getPropagationMode(), is(PropagationMode.DEFAULT_MODE)); + } + + @Test + public void parseReadWriteNoCopyWindows() { + Bind bind = Bind.parse("C:\\host:/container:rw,nocopy"); + assertThat(bind.getPath(), is("C:\\host")); + assertThat(bind.getVolume().getPath(), is("/container")); + assertThat(bind.getAccessMode(), is(rw)); + assertThat(bind.getSecMode(), is(SELContext.none)); + assertThat(bind.getNoCopy(), is(true)); + assertThat(bind.getPropagationMode(), is(PropagationMode.DEFAULT_MODE)); + } + + @Test + public void parseReadWriteSharedWindows() { + Bind bind = Bind.parse("C:\\host:/container:rw,shared"); + assertThat(bind.getPath(), is("C:\\host")); + assertThat(bind.getVolume().getPath(), is("/container")); + assertThat(bind.getAccessMode(), is(rw)); + assertThat(bind.getSecMode(), is(SELContext.none)); + assertThat(bind.getNoCopy(), nullValue()); + assertThat(bind.getPropagationMode(), is(PropagationMode.SHARED)); + } + + @Test + public void parseReadWriteSlaveWindows() { + Bind bind = Bind.parse("C:\\host:/container:rw,slave"); + assertThat(bind.getPath(), is("C:\\host")); + assertThat(bind.getVolume().getPath(), is("/container")); + assertThat(bind.getAccessMode(), is(rw)); + assertThat(bind.getSecMode(), is(SELContext.none)); + assertThat(bind.getNoCopy(), nullValue()); + assertThat(bind.getPropagationMode(), is(PropagationMode.SLAVE)); + } + + @Test + public void parseReadWritePrivateWindows() { + Bind bind = Bind.parse("C:\\host:/container:rw,private"); + assertThat(bind.getPath(), is("C:\\host")); + assertThat(bind.getVolume().getPath(), is("/container")); + assertThat(bind.getAccessMode(), is(rw)); + assertThat(bind.getSecMode(), is(SELContext.none)); + assertThat(bind.getNoCopy(), nullValue()); + assertThat(bind.getPropagationMode(), is(PropagationMode.PRIVATE)); + } + + @Test + public void parseReadOnlyWindows() { + Bind bind = Bind.parse("C:\\host:/container:ro"); + assertThat(bind.getPath(), is("C:\\host")); + assertThat(bind.getVolume().getPath(), is("/container")); + assertThat(bind.getAccessMode(), is(ro)); + assertThat(bind.getSecMode(), is(SELContext.none)); + assertThat(bind.getNoCopy(), nullValue()); + assertThat(bind.getPropagationMode(), is(PropagationMode.DEFAULT_MODE)); + } + + @Test + public void parseSELOnlyWindows() { + Bind bind = Bind.parse("C:\\host:/container:Z"); + assertThat(bind.getPath(), is("C:\\host")); + assertThat(bind.getVolume().getPath(), is("/container")); + assertThat(bind.getAccessMode(), is(AccessMode.DEFAULT)); + assertThat(bind.getSecMode(), is(SELContext.single)); + assertThat(bind.getNoCopy(), nullValue()); + assertThat(bind.getPropagationMode(), is(PropagationMode.DEFAULT_MODE)); + + bind = Bind.parse("C:\\host:/container:z"); + assertThat(bind.getPath(), is("C:\\host")); + assertThat(bind.getVolume().getPath(), is("/container")); + assertThat(bind.getAccessMode(), is(AccessMode.DEFAULT)); + assertThat(bind.getSecMode(), is(SELContext.shared)); + assertThat(bind.getNoCopy(), nullValue()); + assertThat(bind.getPropagationMode(), is(PropagationMode.DEFAULT_MODE)); + } + + @Test + public void parseReadWriteSELWindows() { + Bind bind = Bind.parse("C:\\host:/container:rw,Z"); + assertThat(bind.getPath(), is("C:\\host")); + assertThat(bind.getVolume().getPath(), is("/container")); + assertThat(bind.getAccessMode(), is(rw)); + assertThat(bind.getSecMode(), is(SELContext.single)); + assertThat(bind.getNoCopy(), nullValue()); + assertThat(bind.getPropagationMode(), is(PropagationMode.DEFAULT_MODE)); + } + + @Test + public void parseReadOnlySELWindows() { + Bind bind = Bind.parse("C:\\host:/container:ro,z"); + assertThat(bind.getPath(), is("C:\\host")); + assertThat(bind.getVolume().getPath(), is("/container")); + assertThat(bind.getAccessMode(), is(ro)); + assertThat(bind.getSecMode(), is(SELContext.shared)); + assertThat(bind.getNoCopy(), nullValue()); + assertThat(bind.getPropagationMode(), is(PropagationMode.DEFAULT_MODE)); + } + @Test public void parseReadWrite() { Bind bind = Bind.parse("/host:/container:rw");