From d4f30dc6f8ef842e716cf37b850ab9b4fa45869a Mon Sep 17 00:00:00 2001 From: Tom Clegg Date: Thu, 27 Aug 2015 22:33:44 -0400 Subject: [PATCH] 5824: Fix up support for PDH in vhostname. --- services/keep-web/doc.go | 3 ++- services/keep-web/handler.go | 12 ++++++++---- services/keep-web/handler_test.go | 12 +++++++++++- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/services/keep-web/doc.go b/services/keep-web/doc.go index 40ff00a33c..89085600ee 100644 --- a/services/keep-web/doc.go +++ b/services/keep-web/doc.go @@ -74,7 +74,8 @@ // upstream proxy. // // In all of the above forms, the "dl.example.com" part can be -// anything at all. +// anything at all: keep-web ignores everything after the first "." or +// "--". // // In all of the above forms, the "uuid_or_pdh" part can be either a // collection UUID or a portable data hash with the "+" character diff --git a/services/keep-web/handler.go b/services/keep-web/handler.go index 30b4b64850..657c72debd 100644 --- a/services/keep-web/handler.go +++ b/services/keep-web/handler.go @@ -28,7 +28,8 @@ func init() { anonymousTokens = []string{} } -// return s if s is a UUID or a PDH, otherwise "" +// return a UUID or PDH if s begins with a UUID or URL-encoded PDH; +// otherwise return "". func parseCollectionIdFromDNSName(s string) string { // Strip domain. if i := strings.IndexRune(s, '.'); i >= 0 { @@ -40,10 +41,13 @@ func parseCollectionIdFromDNSName(s string) string { if i := strings.Index(s, "--"); i >= 0 { s = s[:i] } - if !arvadosclient.UUIDMatch(s) && !arvadosclient.PDHMatch(s) { - return "" + if arvadosclient.UUIDMatch(s) { + return s } - return s + if pdh := strings.Replace(s, "-", "+", 1); arvadosclient.PDHMatch(pdh) { + return pdh + } + return "" } func (h *handler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) { diff --git a/services/keep-web/handler_test.go b/services/keep-web/handler_test.go index a1f5e1a01b..0494376ea9 100644 --- a/services/keep-web/handler_test.go +++ b/services/keep-web/handler_test.go @@ -93,7 +93,17 @@ func authzViaPOST(r *http.Request, tok string) int { // Try some combinations of {url, token} using the given authorization // mechanism, and verify the result is correct. func doVhostRequests(c *check.C, authz authorizer) { - hostPath := arvadostest.FooCollection + ".example.com/foo" + for _, hostPath := range []string{ + arvadostest.FooCollection + ".example.com/foo", + arvadostest.FooPdh + ".example.com/foo", + strings.Replace(arvadostest.FooPdh, "+", "-", -1) + ".example.com/foo", + } { + c.Log("doRequests: ", hostPath) + doVhostRequestsWithHostPath(c, authz, hostPath) + } +} + +func doVhostRequestsWithHostPath(c *check.C, authz authorizer, hostPath string) { for _, tok := range []string{ arvadostest.ActiveToken, arvadostest.ActiveToken[:15], -- 2.30.2