Skip to content

Commit

Permalink
use app.viam
Browse files Browse the repository at this point in the history
  • Loading branch information
DTCurrie committed Nov 19, 2024
1 parent b751982 commit c4a86f8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
12 changes: 6 additions & 6 deletions web/backto.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ import (
)

var hostnameWhitelist = map[string]bool{
"localhost": true,
"viam.dev": true,
"viam.com": true,
"localhost": true,
"app.viam.dev": true,
"app.viam.com": true,
}

func isWhitelisted(hostname string) bool {
return hostnameWhitelist[hostname]
}

// IsValidBacktoURL returns true if the passed string is a secure URL to a whitelisted
// hostname. The whitelisted hostnames are: "localhost", "viam.dev", and "viam.com".
// hostname. The whitelisted hostnames are: "localhost", "app.viam.dev", and "app.viam.com".
//
// - https://example.com -> false
// - http://viam.com/path/name -> false
// - https://viam.com/path/name -> true
// - http://app.viam.com/path/name -> false
// - https://app.viam.com/path/name -> true
func IsValidBacktoURL(path string) bool {
normalized := strings.ReplaceAll(path, "\\", "/")
url, err := url.ParseRequestURI(normalized)
Expand Down
40 changes: 20 additions & 20 deletions web/backto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,35 @@ func TestIsValidBacktoURL(t *testing.T) {
})

t.Run("rejects invalid production URLs", func(t *testing.T) {
test.That(t, IsValidBacktoURL("http://viam.com"), test.ShouldBeFalse)
test.That(t, IsValidBacktoURL("ftp://viam.com"), test.ShouldBeFalse)
test.That(t, IsValidBacktoURL("://viam.com"), test.ShouldBeFalse)
test.That(t, IsValidBacktoURL("//viam.com"), test.ShouldBeFalse)
test.That(t, IsValidBacktoURL("//viam.com/some/path"), test.ShouldBeFalse)
test.That(t, IsValidBacktoURL("viam.com"), test.ShouldBeFalse)
test.That(t, IsValidBacktoURL("viam.com/some/path"), test.ShouldBeFalse)
test.That(t, IsValidBacktoURL("www.viam.com"), test.ShouldBeFalse)
test.That(t, IsValidBacktoURL("http://app.viam.com"), test.ShouldBeFalse)
test.That(t, IsValidBacktoURL("ftp://app.viam.com"), test.ShouldBeFalse)
test.That(t, IsValidBacktoURL("://app.viam.com"), test.ShouldBeFalse)
test.That(t, IsValidBacktoURL("//app.viam.com"), test.ShouldBeFalse)
test.That(t, IsValidBacktoURL("//app.viam.com/some/path"), test.ShouldBeFalse)
test.That(t, IsValidBacktoURL("app.viam.com"), test.ShouldBeFalse)
test.That(t, IsValidBacktoURL("app.viam.com/some/path"), test.ShouldBeFalse)
test.That(t, IsValidBacktoURL("www.app.viam.com"), test.ShouldBeFalse)
})

t.Run("accepts valid production URLs", func(t *testing.T) {
test.That(t, IsValidBacktoURL("https://viam.com"), test.ShouldBeTrue)
test.That(t, IsValidBacktoURL("https://viam.com/some/path"), test.ShouldBeTrue)
test.That(t, IsValidBacktoURL("https://app.viam.com"), test.ShouldBeTrue)
test.That(t, IsValidBacktoURL("https://app.viam.com/some/path"), test.ShouldBeTrue)
})

t.Run("rejects invalid staging URLs", func(t *testing.T) {
test.That(t, IsValidBacktoURL("http://viam.dev"), test.ShouldBeFalse)
test.That(t, IsValidBacktoURL("ftp://viam.dev"), test.ShouldBeFalse)
test.That(t, IsValidBacktoURL("://viam.dev"), test.ShouldBeFalse)
test.That(t, IsValidBacktoURL("//viam.dev"), test.ShouldBeFalse)
test.That(t, IsValidBacktoURL("//viam.dev/some/path"), test.ShouldBeFalse)
test.That(t, IsValidBacktoURL("viam.dev"), test.ShouldBeFalse)
test.That(t, IsValidBacktoURL("viam.dev/some/path"), test.ShouldBeFalse)
test.That(t, IsValidBacktoURL("www.viam.dev"), test.ShouldBeFalse)
test.That(t, IsValidBacktoURL("http://app.viam.dev"), test.ShouldBeFalse)
test.That(t, IsValidBacktoURL("ftp://app.viam.dev"), test.ShouldBeFalse)
test.That(t, IsValidBacktoURL("://app.viam.dev"), test.ShouldBeFalse)
test.That(t, IsValidBacktoURL("//app.viam.dev"), test.ShouldBeFalse)
test.That(t, IsValidBacktoURL("//app.viam.dev/some/path"), test.ShouldBeFalse)
test.That(t, IsValidBacktoURL("app.viam.dev"), test.ShouldBeFalse)
test.That(t, IsValidBacktoURL("app.viam.dev/some/path"), test.ShouldBeFalse)
test.That(t, IsValidBacktoURL("www.app.viam.dev"), test.ShouldBeFalse)
})

t.Run("accepts valid staging URLs", func(t *testing.T) {
test.That(t, IsValidBacktoURL("https://viam.dev"), test.ShouldBeTrue)
test.That(t, IsValidBacktoURL("https://viam.dev/some/path"), test.ShouldBeTrue)
test.That(t, IsValidBacktoURL("https://app.viam.dev"), test.ShouldBeTrue)
test.That(t, IsValidBacktoURL("https://app.viam.dev/some/path"), test.ShouldBeTrue)
})

t.Run("rejects invalid local URLs", func(t *testing.T) {
Expand Down

0 comments on commit c4a86f8

Please sign in to comment.