2017-07-31 17:23:52 -04:00
|
|
|
// +build windows
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"math/rand"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
winio "github.com/Microsoft/go-winio"
|
2017-09-19 16:12:29 -04:00
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
"github.com/docker/docker/api/types/container"
|
|
|
|
"github.com/docker/docker/api/types/mount"
|
2017-07-31 17:23:52 -04:00
|
|
|
"github.com/go-check/check"
|
2018-03-13 15:28:34 -04:00
|
|
|
"github.com/gotestyourself/gotestyourself/assert"
|
|
|
|
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
2017-09-19 16:12:29 -04:00
|
|
|
"golang.org/x/net/context"
|
2017-07-31 17:23:52 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestContainersAPICreateMountsBindNamedPipe(c *check.C) {
|
2018-02-09 14:39:57 -05:00
|
|
|
testRequires(c, SameHostDaemon, DaemonIsWindowsAtLeastBuild(16299)) // Named pipe support was added in RS3
|
2017-07-31 17:23:52 -04:00
|
|
|
|
|
|
|
// Create a host pipe to map into the container
|
|
|
|
hostPipeName := fmt.Sprintf(`\\.\pipe\docker-cli-test-pipe-%x`, rand.Uint64())
|
|
|
|
pc := &winio.PipeConfig{
|
|
|
|
SecurityDescriptor: "D:P(A;;GA;;;AU)", // Allow all users access to the pipe
|
|
|
|
}
|
|
|
|
l, err := winio.ListenPipe(hostPipeName, pc)
|
|
|
|
if err != nil {
|
|
|
|
c.Fatal(err)
|
|
|
|
}
|
|
|
|
defer l.Close()
|
|
|
|
|
|
|
|
// Asynchronously read data that the container writes to the mapped pipe.
|
|
|
|
var b []byte
|
|
|
|
ch := make(chan error)
|
|
|
|
go func() {
|
|
|
|
conn, err := l.Accept()
|
|
|
|
if err == nil {
|
|
|
|
b, err = ioutil.ReadAll(conn)
|
|
|
|
conn.Close()
|
|
|
|
}
|
|
|
|
ch <- err
|
|
|
|
}()
|
|
|
|
|
|
|
|
containerPipeName := `\\.\pipe\docker-cli-test-pipe`
|
|
|
|
text := "hello from a pipe"
|
|
|
|
cmd := fmt.Sprintf("echo %s > %s", text, containerPipeName)
|
|
|
|
name := "test-bind-npipe"
|
|
|
|
|
2017-09-19 16:12:29 -04:00
|
|
|
ctx := context.Background()
|
|
|
|
client := testEnv.APIClient()
|
|
|
|
_, err = client.ContainerCreate(ctx,
|
|
|
|
&container.Config{
|
|
|
|
Image: testEnv.PlatformDefaults.BaseImage,
|
|
|
|
Cmd: []string{"cmd", "/c", cmd},
|
|
|
|
}, &container.HostConfig{
|
|
|
|
Mounts: []mount.Mount{
|
|
|
|
{
|
|
|
|
Type: "npipe",
|
|
|
|
Source: hostPipeName,
|
|
|
|
Target: containerPipeName,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
nil, name)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(c, err)
|
2017-07-31 17:23:52 -04:00
|
|
|
|
2017-09-19 16:12:29 -04:00
|
|
|
err = client.ContainerStart(ctx, name, types.ContainerStartOptions{})
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(c, err)
|
2017-07-31 17:23:52 -04:00
|
|
|
|
|
|
|
err = <-ch
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(c, err)
|
|
|
|
assert.Check(c, is.Equal(text, strings.TrimSpace(string(b))))
|
2017-07-31 17:23:52 -04:00
|
|
|
}
|