Docker-DCO-1.1-Signed-off-by: Alexandr Morozov <lk4d4math@gmail.com> (github: LK4D4)
| ... | ... |
@@ -1170,3 +1170,28 @@ func TestBuildEntrypointRunCleanup(t *testing.T) {
|
| 1170 | 1170 |
} |
| 1171 | 1171 |
logDone("build - cleanup cmd after RUN")
|
| 1172 | 1172 |
} |
| 1173 |
+ |
|
| 1174 |
+func TestBuldForbiddenContextPath(t *testing.T) {
|
|
| 1175 |
+ name := "testbuildforbidpath" |
|
| 1176 |
+ defer deleteImages(name) |
|
| 1177 |
+ ctx, err := fakeContext(`FROM scratch |
|
| 1178 |
+ ADD ../../ test/ |
|
| 1179 |
+ `, |
|
| 1180 |
+ map[string]string{
|
|
| 1181 |
+ "test.txt": "test1", |
|
| 1182 |
+ "other.txt": "other", |
|
| 1183 |
+ }) |
|
| 1184 |
+ |
|
| 1185 |
+ defer ctx.Close() |
|
| 1186 |
+ if err != nil {
|
|
| 1187 |
+ t.Fatal(err) |
|
| 1188 |
+ } |
|
| 1189 |
+ if _, err := buildImageFromContext(name, ctx, true); err != nil {
|
|
| 1190 |
+ if !strings.Contains(err.Error(), "Forbidden path outside the build context: ../../ (/)") {
|
|
| 1191 |
+ t.Fatal("Wrong error, must be about forbidden ../../ path")
|
|
| 1192 |
+ } |
|
| 1193 |
+ } else {
|
|
| 1194 |
+ t.Fatal("Error must not be nil")
|
|
| 1195 |
+ } |
|
| 1196 |
+ logDone("build - forbidden context path")
|
|
| 1197 |
+} |
| ... | ... |
@@ -414,54 +414,6 @@ func buildImage(context testContextTemplate, t *testing.T, eng *engine.Engine, u |
| 414 | 414 |
return image, err |
| 415 | 415 |
} |
| 416 | 416 |
|
| 417 |
-func TestForbiddenContextPath(t *testing.T) {
|
|
| 418 |
- eng := NewTestEngine(t) |
|
| 419 |
- defer nuke(mkDaemonFromEngine(eng, t)) |
|
| 420 |
- srv := mkServerFromEngine(eng, t) |
|
| 421 |
- |
|
| 422 |
- context := testContextTemplate{`
|
|
| 423 |
- from {IMAGE}
|
|
| 424 |
- maintainer dockerio |
|
| 425 |
- add ../../ test/ |
|
| 426 |
- `, |
|
| 427 |
- [][2]string{{"test.txt", "test1"}, {"other.txt", "other"}}, nil}
|
|
| 428 |
- |
|
| 429 |
- httpServer, err := mkTestingFileServer(context.remoteFiles) |
|
| 430 |
- if err != nil {
|
|
| 431 |
- t.Fatal(err) |
|
| 432 |
- } |
|
| 433 |
- defer httpServer.Close() |
|
| 434 |
- |
|
| 435 |
- idx := strings.LastIndex(httpServer.URL, ":") |
|
| 436 |
- if idx < 0 {
|
|
| 437 |
- t.Fatalf("could not get port from test http server address %s", httpServer.URL)
|
|
| 438 |
- } |
|
| 439 |
- port := httpServer.URL[idx+1:] |
|
| 440 |
- |
|
| 441 |
- iIP := eng.Hack_GetGlobalVar("httpapi.bridgeIP")
|
|
| 442 |
- if iIP == nil {
|
|
| 443 |
- t.Fatal("Legacy bridgeIP field not set in engine")
|
|
| 444 |
- } |
|
| 445 |
- ip, ok := iIP.(net.IP) |
|
| 446 |
- if !ok {
|
|
| 447 |
- panic("Legacy bridgeIP field in engine does not cast to net.IP")
|
|
| 448 |
- } |
|
| 449 |
- dockerfile := constructDockerfile(context.dockerfile, ip, port) |
|
| 450 |
- |
|
| 451 |
- buildfile := server.NewBuildFile(srv, ioutil.Discard, ioutil.Discard, false, true, false, false, ioutil.Discard, utils.NewStreamFormatter(false), nil, nil) |
|
| 452 |
- _, err = buildfile.Build(context.Archive(dockerfile, t)) |
|
| 453 |
- |
|
| 454 |
- if err == nil {
|
|
| 455 |
- t.Log("Error should not be nil")
|
|
| 456 |
- t.Fail() |
|
| 457 |
- } |
|
| 458 |
- |
|
| 459 |
- if err.Error() != "Forbidden path outside the build context: ../../ (/)" {
|
|
| 460 |
- t.Logf("Error message is not expected: %s", err.Error())
|
|
| 461 |
- t.Fail() |
|
| 462 |
- } |
|
| 463 |
-} |
|
| 464 |
- |
|
| 465 | 417 |
func TestBuildADDFileNotFound(t *testing.T) {
|
| 466 | 418 |
eng := NewTestEngine(t) |
| 467 | 419 |
defer nuke(mkDaemonFromEngine(eng, t)) |