diff --git a/decode_test.go b/decode_test.go new file mode 100644 index 0000000..14ba1f2 --- /dev/null +++ b/decode_test.go @@ -0,0 +1,37 @@ +package main + +import ( + "net/http" + "net/http/httptest" + "testing" +) + +func TestHandleInboxNoSignature(t *testing.T) { + s := httptest.NewServer(http.HandlerFunc(handleInbox)) + 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(handleInbox)) + 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") + } +} diff --git a/handle_test.go b/handle_test.go index 371d54b..3b71732 100644 --- a/handle_test.go +++ b/handle_test.go @@ -10,7 +10,7 @@ import ( "testing" "github.com/yukimochi/Activity-Relay/ActivityPub" - keyloader "github.com/yukimochi/Activity-Relay/KeyLoader" + "github.com/yukimochi/Activity-Relay/KeyLoader" ) func TestMain(m *testing.M) { @@ -60,6 +60,7 @@ func TestHandleWebfingerGet(t *testing.T) { t.Fatalf("WebfingerResource's Host not valid.") } } + func TestHandleWebfingerGetBadResource(t *testing.T) { s := httptest.NewServer(http.HandlerFunc(handleWebfinger)) defer s.Close() @@ -77,6 +78,7 @@ func TestHandleWebfingerGetBadResource(t *testing.T) { t.Fatalf("Failed - StatusCode is not 404.") } } + func TestHandleWebfingerInvalidMethod(t *testing.T) { s := httptest.NewServer(http.HandlerFunc(handleWebfinger)) defer s.Close() @@ -91,6 +93,7 @@ func TestHandleWebfingerInvalidMethod(t *testing.T) { t.Fatalf("Failed - StatusCode is not 400.") } } + func TestHandleActorGet(t *testing.T) { s := httptest.NewServer(http.HandlerFunc(handleActor)) defer s.Close()