2755: add support for signed locators in the Python SDK.
[arvados.git] / services / keep / src / keep / handler_test.go
index 8e7bfea468ca10661a9e77635cb2ab355480bb30..c96086fe7f59f3fb197668501d536a9a759db5a5 100644 (file)
@@ -15,6 +15,7 @@ import (
        "net/http"
        "net/http/httptest"
        "regexp"
+       "strings"
        "testing"
        "time"
 )
@@ -159,7 +160,9 @@ func TestPutHandler(t *testing.T) {
 
        ExpectStatusCode(t,
                "Unauthenticated request, no server key", http.StatusOK, response)
-       ExpectBody(t, "Unauthenticated request, no server key", TEST_HASH, response)
+       ExpectBody(t,
+               "Unauthenticated request, no server key",
+               TEST_HASH_PUT_RESPONSE, response)
 
        // ------------------
        // With a server key.
@@ -183,10 +186,11 @@ func TestPutHandler(t *testing.T) {
        ExpectStatusCode(t,
                "Authenticated PUT, signed locator, with server key",
                http.StatusOK, response)
-       if !VerifySignature(response.Body.String(), known_token) {
+       response_locator := strings.TrimSpace(response.Body.String())
+       if !VerifySignature(response_locator, known_token) {
                t.Errorf("Authenticated PUT, signed locator, with server key:\n"+
                        "response '%s' does not contain a valid signature",
-                       response.Body.String())
+                       response_locator)
        }
 
        // Unauthenticated PUT, unsigned locator
@@ -203,7 +207,7 @@ func TestPutHandler(t *testing.T) {
                http.StatusOK, response)
        ExpectBody(t,
                "Unauthenticated PUT, unsigned locator, with server key",
-               TEST_HASH, response)
+               TEST_HASH_PUT_RESPONSE, response)
 }
 
 // Test /index requests:
@@ -407,7 +411,7 @@ func IssueRequest(router *mux.Router, rt *RequestTester) *httptest.ResponseRecor
        body := bytes.NewReader(rt.request_body)
        req, _ := http.NewRequest(rt.method, rt.uri, body)
        if rt.api_token != "" {
-               req.Header.Set("Authorization", "OAuth "+rt.api_token)
+               req.Header.Set("Authorization", "OAuth2 "+rt.api_token)
        }
        router.ServeHTTP(response, req)
        return response