-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request moby#16859 from diogomonica/changing-trust-server-…
…checks Changing trustServer allowed URL validation
- Loading branch information
Showing
4 changed files
with
75 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package client | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/docker/docker/registry" | ||
) | ||
|
||
func unsetENV() { | ||
os.Unsetenv("DOCKER_CONTENT_TRUST") | ||
os.Unsetenv("DOCKER_CONTENT_TRUST_SERVER") | ||
} | ||
|
||
func TestENVTrustServer(t *testing.T) { | ||
defer unsetENV() | ||
indexInfo := ®istry.IndexInfo{Name: "testserver"} | ||
if err := os.Setenv("DOCKER_CONTENT_TRUST_SERVER", "https://notary-test.com:5000"); err != nil { | ||
t.Fatal("Failed to set ENV variable") | ||
} | ||
output, err := trustServer(indexInfo) | ||
expectedStr := "https://notary-test.com:5000" | ||
if err != nil || output != expectedStr { | ||
t.Fatalf("Expected server to be %s, got %s", expectedStr, output) | ||
} | ||
} | ||
|
||
func TestHTTPENVTrustServer(t *testing.T) { | ||
defer unsetENV() | ||
indexInfo := ®istry.IndexInfo{Name: "testserver"} | ||
if err := os.Setenv("DOCKER_CONTENT_TRUST_SERVER", "http://notary-test.com:5000"); err != nil { | ||
t.Fatal("Failed to set ENV variable") | ||
} | ||
_, err := trustServer(indexInfo) | ||
if err == nil { | ||
t.Fatal("Expected error with invalid scheme") | ||
} | ||
} | ||
|
||
func TestOfficialTrustServer(t *testing.T) { | ||
indexInfo := ®istry.IndexInfo{Name: "testserver", Official: true} | ||
output, err := trustServer(indexInfo) | ||
if err != nil || output != registry.NotaryServer { | ||
t.Fatalf("Expected server to be %s, got %s", registry.NotaryServer, output) | ||
} | ||
} | ||
|
||
func TestNonOfficialTrustServer(t *testing.T) { | ||
indexInfo := ®istry.IndexInfo{Name: "testserver", Official: false} | ||
output, err := trustServer(indexInfo) | ||
expectedStr := "https://" + indexInfo.Name | ||
if err != nil || output != expectedStr { | ||
t.Fatalf("Expected server to be %s, got %s", expectedStr, output) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters