From fbb68d995b8ab7b0a72509040c06e9d395cc85a4 Mon Sep 17 00:00:00 2001 From: Maxim Lebedev Date: Thu, 30 Dec 2021 01:45:31 +0500 Subject: [PATCH] :fire: Removed authn package --- internal/authn/repository.go | 7 --- internal/authn/repository/http/http_authn.go | 55 ------------------- .../authn/repository/http/http_authn_test.go | 50 ----------------- 3 files changed, 112 deletions(-) delete mode 100644 internal/authn/repository.go delete mode 100644 internal/authn/repository/http/http_authn.go delete mode 100644 internal/authn/repository/http/http_authn_test.go diff --git a/internal/authn/repository.go b/internal/authn/repository.go deleted file mode 100644 index 4d44d6e..0000000 --- a/internal/authn/repository.go +++ /dev/null @@ -1,7 +0,0 @@ -package authn - -import "context" - -type Repository interface { - Fetch(ctx context.Context, me string) ([]string, error) -} diff --git a/internal/authn/repository/http/http_authn.go b/internal/authn/repository/http/http_authn.go deleted file mode 100644 index 36ed430..0000000 --- a/internal/authn/repository/http/http_authn.go +++ /dev/null @@ -1,55 +0,0 @@ -package http - -import ( - "bytes" - "context" - "net/url" - - "github.com/pkg/errors" - http "github.com/valyala/fasthttp" - "willnorris.com/go/microformats" - - "source.toby3d.me/website/oauth/internal/authn" -) - -type httpAuthnRepository struct { - client *http.Client -} - -func NewHTTPAuthnRepository(client *http.Client) authn.Repository { - return &httpAuthnRepository{ - client: client, - } -} - -func (repo *httpAuthnRepository) Fetch(ctx context.Context, me string) ([]string, error) { - u, err := url.Parse(me) - if err != nil { - return nil, errors.Wrap(err, "failed to parse me as url") - } - - req := http.AcquireRequest() - defer http.ReleaseRequest(req) - req.SetRequestURI(u.String()) - req.Header.SetMethod(http.MethodGet) - - resp := http.AcquireResponse() - defer http.ReleaseResponse(resp) - - if err := repo.client.Do(req, resp); err != nil { - return nil, errors.Wrap(err, "failed to make a request to the entered me") - } - - data := microformats.Parse(bytes.NewReader(resp.Body()), u) - authn := make([]string, 0) - - for rel, values := range data.Rels { - if rel != "authn" { - continue - } - - authn = append(authn, values...) - } - - return authn, nil -} diff --git a/internal/authn/repository/http/http_authn_test.go b/internal/authn/repository/http/http_authn_test.go deleted file mode 100644 index dffa75f..0000000 --- a/internal/authn/repository/http/http_authn_test.go +++ /dev/null @@ -1,50 +0,0 @@ -package http_test - -import ( - "context" - "testing" - - "github.com/stretchr/testify/assert" - http "github.com/valyala/fasthttp" - - repository "source.toby3d.me/website/oauth/internal/authn/repository/http" - "source.toby3d.me/website/oauth/internal/common" - "source.toby3d.me/website/oauth/internal/util" -) - -const testBody string = ` - - - - - - Example Profile - - - -
- - Unsecure profile - Secure profile -
- - -` - -func TestFetch(t *testing.T) { - t.Parallel() - - client, _, cleanup := util.TestServe(t, func(ctx *http.RequestCtx) { - ctx.SetStatusCode(http.StatusOK) - ctx.SetContentType(common.MIMETextHTML) - ctx.SetBodyString(testBody) - }) - t.Cleanup(cleanup) - - result, err := repository.NewHTTPAuthnRepository(client).Fetch(context.TODO(), "https://example.com/") - assert.NoError(t, err) - assert.Equal(t, []string{ - "https://user.example.com/", - "https://user.example.net/", - }, result) -}