5824: Fix up support for PDH in vhostname.
authorTom Clegg <tom@curoverse.com>
Fri, 28 Aug 2015 02:33:44 +0000 (22:33 -0400)
committerTom Clegg <tom@curoverse.com>
Sat, 17 Oct 2015 00:01:03 +0000 (20:01 -0400)
services/keep-web/doc.go
services/keep-web/handler.go
services/keep-web/handler_test.go

index 40ff00a33c7ce11cfbf260e0978c5da7a69dbe79..89085600eeeed6d3bd4a4e208923534d7dd195e4 100644 (file)
@@ -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
index 30b4b64850571ec3ca456f208f2ac24ba4d60683..657c72debdd2b615a03a281ed3f6593bb41af0e4 100644 (file)
@@ -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) {
index a1f5e1a01b64b33fcbf8b80cdc8beeed684d72b2..0494376ea98565c9d76e4ec1932de54eb9f9f3d3 100644 (file)
@@ -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],