| 404 | } |
| 405 | |
| 406 | func TestHttpGetter_auth(t *testing.T) { |
| 407 | ln := testHttpServer(t) |
| 408 | defer ln.Close() |
| 409 | ctx := context.Background() |
| 410 | |
| 411 | g := new(HttpGetter) |
| 412 | dst := testing_helper.TempDir(t) |
| 413 | defer os.RemoveAll(dst) |
| 414 | |
| 415 | var u url.URL |
| 416 | u.Scheme = "http" |
| 417 | u.Host = ln.Addr().String() |
| 418 | u.Path = "/meta-auth" |
| 419 | u.User = url.UserPassword("foo", "bar") |
| 420 | |
| 421 | req := &Request{ |
| 422 | Dst: dst, |
| 423 | Src: u.String(), |
| 424 | u: &u, |
| 425 | GetMode: ModeDir, |
| 426 | } |
| 427 | |
| 428 | // Get it, which should error because it uses the file protocol. |
| 429 | err := g.Get(ctx, req) |
| 430 | if !strings.Contains(err.Error(), "no getter available for X-Terraform-Get source protocol:") { |
| 431 | t.Fatalf("unexpected error: %v", err) |
| 432 | } |
| 433 | // But, using a wrapper client with a file getter will work. |
| 434 | c := &Client{ |
| 435 | Getters: []Getter{ |
| 436 | g, |
| 437 | new(FileGetter), |
| 438 | }, |
| 439 | } |
| 440 | |
| 441 | if _, err = c.Get(ctx, req); err != nil { |
| 442 | t.Fatalf("err: %s", err) |
| 443 | } |
| 444 | |
| 445 | // Verify the main file exists |
| 446 | mainPath := filepath.Join(dst, "main.tf") |
| 447 | if _, err := os.Stat(mainPath); err != nil { |
| 448 | t.Fatalf("err: %s", err) |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | func TestHttpGetter_authNetrc(t *testing.T) { |
| 453 | ln := testHttpServer(t) |