From a8c36706a930aa4127d753bea4c1dc599dec8305 Mon Sep 17 00:00:00 2001 From: tsmethurst Date: Sat, 20 Mar 2021 23:29:11 +0100 Subject: [PATCH] some fiddling --- internal/oauth/oauth_test.go | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/internal/oauth/oauth_test.go b/internal/oauth/oauth_test.go index 6c3a17c..27a854c 100644 --- a/internal/oauth/oauth_test.go +++ b/internal/oauth/oauth_test.go @@ -32,7 +32,18 @@ const () // SetupSuite sets some variables on the suite that we can use as consts (more or less) throughout func (suite *OauthTestSuite) SetupSuite() { - encryptedPassword, err := bcrypt.GenerateFromPassword([]byte("test-password"), bcrypt.DefaultCost) + c := config.Empty() + // we're running on localhost without https so set the protocol to http + c.Protocol = "http" + // just for testing + c.Host = "localhost:8080" + // because go tests are run within the test package directory, we need to fiddle with the templateconfig + // basedir in a way that we wouldn't normally have to do when running the binary, in order to make + // the templates actually load + c.TemplateConfig.BaseDir = "../../web/template/" + suite.config = c + + encryptedPassword, err := bcrypt.GenerateFromPassword([]byte("password"), bcrypt.DefaultCost) if err != nil { logrus.Panicf("error encrypting user pass: %s", err) } @@ -40,21 +51,14 @@ func (suite *OauthTestSuite) SetupSuite() { suite.testAccount = >smodel.Account{} suite.testUser = >smodel.User{ EncryptedPassword: string(encryptedPassword), - Email: "user@localhost", + Email: "user@example.org", AccountID: "some-account-id-it-doesn't-matter-really-since-this-user-doesn't-actually-have-an-account!", } suite.testClient = &oauthClient{ ID: "a-known-client-id", Secret: "some-secret", - Domain: "http://localhost:8080", + Domain: fmt.Sprintf("%s://%s", c.Protocol, c.Host), } - - // because go tests are run within the test package directory, we need to fiddle with the templateconfig - // basedir in a way that we wouldn't normally have to do when running the binary, in order to make - // the templates actually load - c := config.Empty() - c.TemplateConfig.BaseDir = "../../web/template/" - suite.config = c } // SetupTest creates a postgres connection and creates the oauth_clients table before each test @@ -123,9 +127,9 @@ func (suite *OauthTestSuite) TestAPIInitialize() { suite.FailNow(fmt.Sprintf("error initializing api: %s", err)) } go r.Start() - time.Sleep(30 * time.Second) - // http://localhost:8080/oauth/authorize?client_id=a-known-client-id&response_type=code&redirect_uri=https://example.org - // http://localhost:8080/oauth/authorize?client_id=a-known-client-id&response_type=code&redirect_uri=urn:ietf:wg:oauth:2.0:oob + time.Sleep(60 * time.Second) + // http://localhost:8080/oauth/authorize?client_id=a-known-client-id&response_type=code&redirect_uri=http://localhost:8080 + // curl -v -F client_id=a-known-client-id -F client_secret=some-secret -F redirect_uri=http://localhost:8080 -F code=[ INSERT CODE HERE ] -F grant_type=authorization_code localhost:8080/oauth/token } func TestOauthTestSuite(t *testing.T) {