diff options
Diffstat (limited to 'client')
-rw-r--r-- | client/client.go | 4 | ||||
-rw-r--r-- | client/client_test.go | 36 |
2 files changed, 1 insertions, 39 deletions
diff --git a/client/client.go b/client/client.go index af7c2d8..b68b2be 100644 --- a/client/client.go +++ b/client/client.go @@ -16,9 +16,6 @@ type CaesarClient struct { // Endpoint is the URL to which HTTP requests should be made Endpoint string - // Token is an authorization token to supply to the server - Token string - c *http.Client once sync.Once } @@ -33,7 +30,6 @@ func (c *CaesarClient) EncodeMessage(r io.Reader) (io.Reader, error) { if err != nil { return nil, err } - req.Header.Set("authorization", "token "+c.Token) req.Header.Set("user-agent", "caesar-client/1.0") resp, err := c.c.Do(req) if err != nil { diff --git a/client/client_test.go b/client/client_test.go index 9ccc149..b6af2b9 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -8,40 +8,6 @@ import ( "testing" ) -func TestBadAuth(t *testing.T) { - var hf http.HandlerFunc = func(w http.ResponseWriter, r *http.Request) { - if r.Header.Get("authorization") != "token TEST-TOKEN" { - w.WriteHeader(http.StatusUnauthorized) - return - } - w.Write([]byte("encoded yay")) - } - tests := []struct { - name string - tok string - expectErr bool - expectBody bool - }{ - {"valid token", "TEST-TOKEN", false, true}, - {"empty token", "", true, false}, - {"invalid token", "bad token", true, false}, - } - server := httptest.NewServer(hf) - defer server.Close() - c := CaesarClient{Endpoint: server.URL} - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - r, err := c.EncodeMessage(strings.NewReader("secret message")) - if err == nil { - t.Errorf("should have gotten error") - } - if r != nil { - t.Errorf("should not have gotten a reader") - } - }) - } -} - func TestEncode(t *testing.T) { var hf http.HandlerFunc = func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("response")) @@ -54,7 +20,7 @@ func TestEncode(t *testing.T) { t.Errorf("should not have gotten error: %v", err) } if r == nil { - t.Errorf("should have gotten a reader") + t.Fatalf("should have gotten a reader") } resp, err := ioutil.ReadAll(r) if err != nil { |