diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/auth.go | 15 | ||||
-rw-r--r-- | server/main.go | 8 | ||||
-rw-r--r-- | server/main_test.go | 25 | ||||
-rwxr-xr-x | server/server | bin | 7349148 -> 7349116 bytes |
4 files changed, 5 insertions, 43 deletions
diff --git a/server/auth.go b/server/auth.go deleted file mode 100644 index 15ea164..0000000 --- a/server/auth.go +++ /dev/null @@ -1,15 +0,0 @@ -package main - -import ( - "net/http" -) - -// An Authenticator takes an HTTP request and returns true iff it is allowed to -// use our service. -type Authenticator func(req *http.Request) bool - -func TokenAuthenticator() Authenticator { - return func(req *http.Request) bool { - return req.Header.Get("authorization") == "magic" - } -} diff --git a/server/main.go b/server/main.go index 23f2959..9ebcb22 100644 --- a/server/main.go +++ b/server/main.go @@ -8,16 +8,12 @@ import ( ) func main() { - server := handleCaesar(TokenAuthenticator()) + server := handleCaesar() http.ListenAndServe(":8088", server) } -func handleCaesar(auth Authenticator) http.HandlerFunc { +func handleCaesar() http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - if !auth(r) { - w.WriteHeader(http.StatusUnauthorized) - return - } if r.Method != http.MethodPost { w.WriteHeader(http.StatusBadRequest) return diff --git a/server/main_test.go b/server/main_test.go index 75ddcdb..e588ae1 100644 --- a/server/main_test.go +++ b/server/main_test.go @@ -7,13 +7,12 @@ import ( "testing" ) -func TestHandleCaesarAllowed(t *testing.T) { - allowAll := func(r *http.Request) bool { return true } +func TestHandleCaesar(t *testing.T) { bodyReader := strings.NewReader("hello world") req := httptest.NewRequest("POST", "/", bodyReader) resp := httptest.NewRecorder() - handler := handleCaesar(allowAll) + handler := handleCaesar() handler(resp, req) if resp.Code != http.StatusOK { @@ -26,28 +25,10 @@ func TestHandleCaesarAllowed(t *testing.T) { } } -func TestCaesarNotAllowed(t *testing.T) { - denyAll := func(r *http.Request) bool { return false } - req := httptest.NewRequest("POST", "/", nil) - resp := httptest.NewRecorder() - - handler := handleCaesar(denyAll) - handler(resp, req) - - if resp.Code != http.StatusUnauthorized { - t.Errorf("should not have been authorized") - } - - if len(resp.Body.Bytes()) != 0 { - t.Errorf("should not have gotten a response body") - } -} - func TestCaesarBadRequest(t *testing.T) { - allowAll := func(r *http.Request) bool { return true } req := httptest.NewRequest("GET", "/", nil) resp := httptest.NewRecorder() - handler := handleCaesar(allowAll) + handler := handleCaesar() handler(resp, req) if resp.Code != http.StatusBadRequest { t.Errorf("status should have been bad request, got %d", resp.Code) diff --git a/server/server b/server/server Binary files differindex 979db70..25d8f3f 100755 --- a/server/server +++ b/server/server |