some fiddling

This commit is contained in:
tsmethurst 2021-03-20 23:29:11 +01:00
commit a8c36706a9

View file

@ -32,7 +32,18 @@ const ()
// SetupSuite sets some variables on the suite that we can use as consts (more or less) throughout // SetupSuite sets some variables on the suite that we can use as consts (more or less) throughout
func (suite *OauthTestSuite) SetupSuite() { 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 { if err != nil {
logrus.Panicf("error encrypting user pass: %s", err) logrus.Panicf("error encrypting user pass: %s", err)
} }
@ -40,21 +51,14 @@ func (suite *OauthTestSuite) SetupSuite() {
suite.testAccount = &gtsmodel.Account{} suite.testAccount = &gtsmodel.Account{}
suite.testUser = &gtsmodel.User{ suite.testUser = &gtsmodel.User{
EncryptedPassword: string(encryptedPassword), 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!", AccountID: "some-account-id-it-doesn't-matter-really-since-this-user-doesn't-actually-have-an-account!",
} }
suite.testClient = &oauthClient{ suite.testClient = &oauthClient{
ID: "a-known-client-id", ID: "a-known-client-id",
Secret: "some-secret", 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 // 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)) suite.FailNow(fmt.Sprintf("error initializing api: %s", err))
} }
go r.Start() go r.Start()
time.Sleep(30 * time.Second) time.Sleep(60 * 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=http://localhost:8080
// http://localhost:8080/oauth/authorize?client_id=a-known-client-id&response_type=code&redirect_uri=urn:ietf:wg:oauth:2.0:oob // 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) { func TestOauthTestSuite(t *testing.T) {