Explorar o código

Prevent Tests from creating users on Prod Index

The integration tests had previously used the environment variable
DOCKER_INDEX_URL but it was apparently removed several months ago.

Change the integration auth tests to specify the ServerAddress field
of the AuthConfig struct to use the staging deployment of the index.

Docker-DCO-1.1-Signed-off-by: Josh Hawn <josh.hawn@docker.com> (github: jlhawn)
Josh Hawn %!s(int64=11) %!d(string=hai) anos
pai
achega
c914abaf15
Modificáronse 1 ficheiros con 17 adicións e 6 borrados
  1. 17 6
      integration/auth_test.go

+ 17 - 6
integration/auth_test.go

@@ -3,6 +3,7 @@ package docker
 import (
 import (
 	"crypto/rand"
 	"crypto/rand"
 	"encoding/hex"
 	"encoding/hex"
+	"fmt"
 	"github.com/dotcloud/docker/auth"
 	"github.com/dotcloud/docker/auth"
 	"os"
 	"os"
 	"strings"
 	"strings"
@@ -17,7 +18,12 @@ import (
 func TestLogin(t *testing.T) {
 func TestLogin(t *testing.T) {
 	os.Setenv("DOCKER_INDEX_URL", "https://indexstaging-docker.dotcloud.com")
 	os.Setenv("DOCKER_INDEX_URL", "https://indexstaging-docker.dotcloud.com")
 	defer os.Setenv("DOCKER_INDEX_URL", "")
 	defer os.Setenv("DOCKER_INDEX_URL", "")
-	authConfig := &auth.AuthConfig{Username: "unittester", Password: "surlautrerivejetattendrai", Email: "noise+unittester@dotcloud.com"}
+	authConfig := &auth.AuthConfig{
+		Username:      "unittester",
+		Password:      "surlautrerivejetattendrai",
+		Email:         "noise+unittester@docker.com",
+		ServerAddress: "https://indexstaging-docker.dotcloud.com/v1/",
+	}
 	status, err := auth.Login(authConfig, nil)
 	status, err := auth.Login(authConfig, nil)
 	if err != nil {
 	if err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
@@ -28,8 +34,6 @@ func TestLogin(t *testing.T) {
 }
 }
 
 
 func TestCreateAccount(t *testing.T) {
 func TestCreateAccount(t *testing.T) {
-	os.Setenv("DOCKER_INDEX_URL", "https://indexstaging-docker.dotcloud.com")
-	defer os.Setenv("DOCKER_INDEX_URL", "")
 	tokenBuffer := make([]byte, 16)
 	tokenBuffer := make([]byte, 16)
 	_, err := rand.Read(tokenBuffer)
 	_, err := rand.Read(tokenBuffer)
 	if err != nil {
 	if err != nil {
@@ -37,13 +41,20 @@ func TestCreateAccount(t *testing.T) {
 	}
 	}
 	token := hex.EncodeToString(tokenBuffer)[:12]
 	token := hex.EncodeToString(tokenBuffer)[:12]
 	username := "ut" + token
 	username := "ut" + token
-	authConfig := &auth.AuthConfig{Username: username, Password: "test42", Email: "docker-ut+" + token + "@example.com"}
+	authConfig := &auth.AuthConfig{
+		Username:      username,
+		Password:      "test42",
+		Email:         fmt.Sprintf("docker-ut+%s@example.com", token),
+		ServerAddress: "https://indexstaging-docker.dotcloud.com/v1/",
+	}
 	status, err := auth.Login(authConfig, nil)
 	status, err := auth.Login(authConfig, nil)
 	if err != nil {
 	if err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
-	expectedStatus := "Account created. Please use the confirmation link we sent" +
-		" to your e-mail to activate it."
+	expectedStatus := fmt.Sprintf(
+		"Account created. Please see the documentation of the registry %s for instructions how to activate it.",
+		authConfig.ServerAddress,
+	)
 	if status != expectedStatus {
 	if status != expectedStatus {
 		t.Fatalf("Expected status: \"%s\", found \"%s\" instead.", expectedStatus, status)
 		t.Fatalf("Expected status: \"%s\", found \"%s\" instead.", expectedStatus, status)
 	}
 	}