Refactored metadata HTTP delivery test

This commit is contained in:
Maxim Lebedev 2024-05-08 16:44:10 +05:00
parent d789bfd1c7
commit 48c5423ae1
Signed by: toby3d
GPG Key ID: 1F14E25B7C119FC5
2 changed files with 6 additions and 10 deletions

View File

@ -1,25 +1,23 @@
package http_test
import (
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
"source.toby3d.me/toby3d/auth/internal/domain"
delivery "source.toby3d.me/toby3d/auth/internal/metadata/delivery/http"
testutil "source.toby3d.me/toby3d/auth/internal/util/testing"
)
func TestMetadata(t *testing.T) {
func TestHandler_ServeHTTP(t *testing.T) {
t.Parallel()
metadata := domain.TestMetadata(t)
req := httptest.NewRequest(http.MethodGet, "https://example.com/.well-known/oauth-authorization-server", nil)
w := httptest.NewRecorder()
delivery.NewHandler(metadata).
ServeHTTP(w, req)
delivery.NewHandler(metadata).ServeHTTP(w, req)
resp := w.Result()
@ -27,8 +25,5 @@ func TestMetadata(t *testing.T) {
t.Errorf("%s %s = %d, want %d", req.Method, req.RequestURI, resp.StatusCode, http.StatusOK)
}
out := new(delivery.MetadataResponse)
if err := json.NewDecoder(resp.Body).Decode(out); err != nil {
t.Fatal(err)
}
testutil.GoldenEqual(t, resp.Body)
}

View File

@ -0,0 +1 @@
{"service_documentation":"https://indieauth.net/draft/","authorization_endpoint":"https://indieauth.example.com/auth","token_endpoint":"https://indieauth.example.com/token","introspection_endpoint":"https://indieauth.example.com/introspect","userinfo_endpoint":"https://indieauth.example.com/userinfo","revocation_endpoint":"https://indieauth.example.com/revocation","issuer":"https://example.com/.well-known/oauth-authorization-server","revocation_endpoint_auth_methods_supported":["none"],"response_types_supported":["code","id"],"grant_types_supported":["authorization_code","ticket"],"scopes_supported":["block","channels","create","delete","draft","email","follow","media","mute","profile","read","update"],"code_challenge_methods_supported":["MD5","PLAIN","S1","S256","S512"],"introspection_endpoint_auth_methods_supported":["Bearer"],"authorization_response_iss_parameter_supported":true}