2021-12-28 01:28:10 +00:00
|
|
|
package http_test
|
|
|
|
|
|
|
|
import (
|
2022-02-01 18:26:55 +00:00
|
|
|
"reflect"
|
2021-12-28 01:28:10 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/fasthttp/router"
|
2022-01-13 20:43:07 +00:00
|
|
|
"github.com/goccy/go-json"
|
2021-12-28 01:28:10 +00:00
|
|
|
http "github.com/valyala/fasthttp"
|
|
|
|
|
2022-01-04 17:31:33 +00:00
|
|
|
"source.toby3d.me/website/indieauth/internal/domain"
|
|
|
|
delivery "source.toby3d.me/website/indieauth/internal/metadata/delivery/http"
|
|
|
|
"source.toby3d.me/website/indieauth/internal/testing/httptest"
|
2021-12-28 01:28:10 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestMetadata(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
r := router.New()
|
|
|
|
cfg := domain.TestConfig(t)
|
2021-12-29 20:43:01 +00:00
|
|
|
delivery.NewRequestHandler(cfg).Register(r)
|
2021-12-28 01:28:10 +00:00
|
|
|
|
|
|
|
client, _, cleanup := httptest.New(t, r.Handler)
|
|
|
|
t.Cleanup(cleanup)
|
|
|
|
|
2022-02-01 18:26:55 +00:00
|
|
|
const requestURL string = "https://example.com/.well-known/oauth-authorization-server"
|
|
|
|
|
|
|
|
status, body, err := client.Get(nil, requestURL)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if status != http.StatusOK {
|
|
|
|
t.Errorf("GET %s = %d, want %d", requestURL, status, http.StatusOK)
|
|
|
|
}
|
2021-12-28 01:28:10 +00:00
|
|
|
|
|
|
|
result := new(delivery.MetadataResponse)
|
2022-02-01 18:26:55 +00:00
|
|
|
if err = json.Unmarshal(body, result); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expResult := delivery.DefaultMetadataResponse
|
|
|
|
expResult.Issuer = cfg.Server.GetRootURL()
|
|
|
|
expResult.AuthorizationEndpoint = expResult.Issuer + "authorize"
|
|
|
|
expResult.TokenEndpoint = expResult.Issuer + "token"
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(*result, expResult) {
|
|
|
|
t.Errorf("Unmarshal(%s) = %+v, want %+v", body, result, expResult)
|
|
|
|
}
|
2021-12-28 01:28:10 +00:00
|
|
|
}
|