42 lines
934 B
Go
42 lines
934 B
Go
package main
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
)
|
|
|
|
func TestHandleInboxNoSignature(t *testing.T) {
|
|
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
handleInbox(w, r, decodeActivity)
|
|
}))
|
|
defer s.Close()
|
|
|
|
req, _ := http.NewRequest("POST", s.URL, nil)
|
|
client := new(http.Client)
|
|
r, err := client.Do(req)
|
|
if err != nil {
|
|
t.Fatalf("Failed - " + err.Error())
|
|
}
|
|
if r.StatusCode != 400 {
|
|
t.Fatalf("Failed - StatusCode is not 400")
|
|
}
|
|
}
|
|
|
|
func TestHandleInboxInvalidMethod(t *testing.T) {
|
|
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
handleInbox(w, r, decodeActivity)
|
|
}))
|
|
defer s.Close()
|
|
|
|
req, _ := http.NewRequest("GET", s.URL, nil)
|
|
client := new(http.Client)
|
|
r, err := client.Do(req)
|
|
if err != nil {
|
|
t.Fatalf("Failed - " + err.Error())
|
|
}
|
|
if r.StatusCode != 404 {
|
|
t.Fatalf("Failed - StatusCode is not 404")
|
|
}
|
|
}
|