Skip to content

Commit 01621b3

Browse files
committed
Add a test to check for double :ro
Signed-off-by: David Gageot <[email protected]>
1 parent 7565889 commit 01621b3

File tree

1 file changed

+35
-7
lines changed

1 file changed

+35
-7
lines changed

cmd/docker-mcp/internal/gateway/clientpool_test.go

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ grafana:
3030
"grafana.api_key": "API_KEY",
3131
}
3232

33-
args, env := argsAndEnv(t, "grafana", catalogYAML, configYAML, secrets)
33+
args, env := argsAndEnv(t, "grafana", catalogYAML, configYAML, secrets, nil)
3434

3535
assert.Equal(t, []string{
3636
"run", "--rm", "-i", "--init", "--security-opt", "no-new-privileges", "--cpus", "1", "--memory", "2Gb", "--pull", "never",
@@ -50,7 +50,7 @@ secrets:
5050
"mongodb.connection_string": "HOST:PORT",
5151
}
5252

53-
args, env := argsAndEnv(t, "mongodb", catalogYAML, "", secrets)
53+
args, env := argsAndEnv(t, "mongodb", catalogYAML, "", secrets, nil)
5454

5555
assert.Equal(t, []string{
5656
"run", "--rm", "-i", "--init", "--security-opt", "no-new-privileges", "--cpus", "1", "--memory", "2Gb", "--pull", "never",
@@ -74,7 +74,7 @@ env:
7474
"notion.internal_integration_token": "ntn_DUMMY",
7575
}
7676

77-
args, env := argsAndEnv(t, "notion", catalogYAML, "", secrets)
77+
args, env := argsAndEnv(t, "notion", catalogYAML, "", secrets, nil)
7878

7979
assert.Equal(t, []string{
8080
"run", "--rm", "-i", "--init", "--security-opt", "no-new-privileges", "--cpus", "1", "--memory", "2Gb", "--pull", "never",
@@ -94,7 +94,7 @@ hub:
9494
log_path: /local/logs
9595
`
9696

97-
args, env := argsAndEnv(t, "hub", catalogYAML, configYAML, nil)
97+
args, env := argsAndEnv(t, "hub", catalogYAML, configYAML, nil, nil)
9898

9999
assert.Equal(t, []string{
100100
"run", "--rm", "-i", "--init", "--security-opt", "no-new-privileges", "--cpus", "1", "--memory", "2Gb", "--pull", "never",
@@ -110,7 +110,7 @@ volumes:
110110
- '{{hub.log_path|mount_as:/logs:ro}}'
111111
`
112112

113-
args, env := argsAndEnv(t, "hub", catalogYAML, "", nil)
113+
args, env := argsAndEnv(t, "hub", catalogYAML, "", nil, nil)
114114

115115
assert.Equal(t, []string{
116116
"run", "--rm", "-i", "--init", "--security-opt", "no-new-privileges", "--cpus", "1", "--memory", "2Gb", "--pull", "never",
@@ -119,7 +119,27 @@ volumes:
119119
assert.Empty(t, env)
120120
}
121121

122-
func argsAndEnv(t *testing.T, name, catalogYAML, configYAML string, secrets map[string]string) ([]string, []string) {
122+
func TestApplyConfigMountAsReadOnly(t *testing.T) {
123+
catalogYAML := `
124+
volumes:
125+
- '{{hub.log_path|mount_as:/logs:ro}}'
126+
`
127+
configYAML := `
128+
hub:
129+
log_path: /local/logs
130+
`
131+
132+
args, env := argsAndEnv(t, "hub", catalogYAML, configYAML, nil, readOnly())
133+
134+
assert.Equal(t, []string{
135+
"run", "--rm", "-i", "--init", "--security-opt", "no-new-privileges", "--cpus", "1", "--memory", "2Gb", "--pull", "never",
136+
"-l", "docker-mcp=true", "-l", "docker-mcp-tool-type=mcp", "-l", "docker-mcp-name=hub", "-l", "docker-mcp-transport=stdio",
137+
"-v", "/local/logs:/logs:ro",
138+
}, args)
139+
assert.Empty(t, env)
140+
}
141+
142+
func argsAndEnv(t *testing.T, name, catalogYAML, configYAML string, secrets map[string]string, readOnly *bool) ([]string, []string) {
123143
t.Helper()
124144

125145
clientPool := &clientPool{
@@ -133,7 +153,7 @@ func argsAndEnv(t *testing.T, name, catalogYAML, configYAML string, secrets map[
133153
Spec: parseSpec(t, catalogYAML),
134154
Config: parseConfig(t, configYAML),
135155
Secrets: secrets,
136-
}, nil, proxies.TargetConfig{})
156+
}, readOnly, proxies.TargetConfig{})
137157
}
138158

139159
func parseSpec(t *testing.T, contentYAML string) catalog.Server {
@@ -151,3 +171,11 @@ func parseConfig(t *testing.T, contentYAML string) map[string]any {
151171
require.NoError(t, err)
152172
return config
153173
}
174+
175+
func readOnly() *bool {
176+
return boolPtr(true)
177+
}
178+
179+
func boolPtr(b bool) *bool {
180+
return &b
181+
}

0 commit comments

Comments
 (0)