mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-03 03:52:25 -06:00
store account + app
This commit is contained in:
parent
67697d558c
commit
1b4025dbfb
1 changed files with 35 additions and 11 deletions
|
|
@ -8,6 +8,7 @@ import (
|
||||||
|
|
||||||
"github.com/go-pg/pg/v10"
|
"github.com/go-pg/pg/v10"
|
||||||
"github.com/go-pg/pg/v10/orm"
|
"github.com/go-pg/pg/v10/orm"
|
||||||
|
"github.com/google/uuid"
|
||||||
"github.com/gotosocial/gotosocial/internal/api"
|
"github.com/gotosocial/gotosocial/internal/api"
|
||||||
"github.com/gotosocial/gotosocial/internal/config"
|
"github.com/gotosocial/gotosocial/internal/config"
|
||||||
"github.com/gotosocial/gotosocial/internal/gtsmodel"
|
"github.com/gotosocial/gotosocial/internal/gtsmodel"
|
||||||
|
|
@ -19,13 +20,14 @@ import (
|
||||||
|
|
||||||
type OauthTestSuite struct {
|
type OauthTestSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
tokenStore oauth2.TokenStore
|
tokenStore oauth2.TokenStore
|
||||||
clientStore oauth2.ClientStore
|
clientStore oauth2.ClientStore
|
||||||
conn *pg.DB
|
conn *pg.DB
|
||||||
testAccount *gtsmodel.Account
|
testAccount *gtsmodel.Account
|
||||||
testUser *gtsmodel.User
|
testApplication *gtsmodel.Application
|
||||||
testClient *oauthClient
|
testUser *gtsmodel.User
|
||||||
config *config.Config
|
testClient *oauthClient
|
||||||
|
config *config.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
|
|
@ -46,17 +48,31 @@ func (suite *OauthTestSuite) SetupSuite() {
|
||||||
logrus.Panicf("error encrypting user pass: %s", err)
|
logrus.Panicf("error encrypting user pass: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
suite.testAccount = >smodel.Account{}
|
acctID := uuid.NewString()
|
||||||
|
|
||||||
|
suite.testAccount = >smodel.Account{
|
||||||
|
ID: acctID,
|
||||||
|
Username: "test_user",
|
||||||
|
}
|
||||||
suite.testUser = >smodel.User{
|
suite.testUser = >smodel.User{
|
||||||
EncryptedPassword: string(encryptedPassword),
|
EncryptedPassword: string(encryptedPassword),
|
||||||
Email: "user@example.org",
|
Email: "user@example.org",
|
||||||
AccountID: "some-account-id-it-doesn't-matter-really-since-this-user-doesn't-actually-have-an-account!",
|
AccountID: acctID,
|
||||||
}
|
}
|
||||||
suite.testClient = &oauthClient{
|
suite.testClient = &oauthClient{
|
||||||
ID: "a-known-client-id",
|
ID: "a-known-client-id",
|
||||||
Secret: "some-secret",
|
Secret: "some-secret",
|
||||||
Domain: fmt.Sprintf("%s://%s", c.Protocol, c.Host),
|
Domain: fmt.Sprintf("%s://%s", c.Protocol, c.Host),
|
||||||
}
|
}
|
||||||
|
suite.testApplication = >smodel.Application{
|
||||||
|
Name: "a test application",
|
||||||
|
Website: "https://some-application-website.com",
|
||||||
|
RedirectURI: "http://localhost:8080",
|
||||||
|
ClientID: "a-known-client-id",
|
||||||
|
ClientSecret: "some-secret",
|
||||||
|
Scopes: "read",
|
||||||
|
VapidKey: uuid.NewString(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
|
|
@ -85,6 +101,10 @@ func (suite *OauthTestSuite) SetupTest() {
|
||||||
suite.tokenStore = NewPGTokenStore(context.Background(), suite.conn, logrus.New())
|
suite.tokenStore = NewPGTokenStore(context.Background(), suite.conn, logrus.New())
|
||||||
suite.clientStore = NewPGClientStore(suite.conn)
|
suite.clientStore = NewPGClientStore(suite.conn)
|
||||||
|
|
||||||
|
if _, err := suite.conn.Model(suite.testAccount).Insert(); err != nil {
|
||||||
|
logrus.Panicf("could not insert test account into db: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
if _, err := suite.conn.Model(suite.testUser).Insert(); err != nil {
|
if _, err := suite.conn.Model(suite.testUser).Insert(); err != nil {
|
||||||
logrus.Panicf("could not insert test user into db: %s", err)
|
logrus.Panicf("could not insert test user into db: %s", err)
|
||||||
}
|
}
|
||||||
|
|
@ -93,6 +113,10 @@ func (suite *OauthTestSuite) SetupTest() {
|
||||||
logrus.Panicf("could not insert test client into db: %s", err)
|
logrus.Panicf("could not insert test client into db: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if _, err := suite.conn.Model(suite.testApplication).Insert(); err != nil {
|
||||||
|
logrus.Panicf("could not insert test application into db: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TearDownTest drops the oauth_clients table and closes the pg connection after each test
|
// TearDownTest drops the oauth_clients table and closes the pg connection after each test
|
||||||
|
|
@ -126,9 +150,9 @@ func (suite *OauthTestSuite) TestAPIInitialize() {
|
||||||
}
|
}
|
||||||
go r.Start()
|
go r.Start()
|
||||||
time.Sleep(60 * time.Second)
|
time.Sleep(60 * time.Second)
|
||||||
// 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=http://localhost:8080&scope=read
|
||||||
// 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
|
// 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
|
||||||
// curl -v -H "Authorization: bearer [INSERT TOKEN HERE]" http://localhost:8080
|
// curl -v -H "Authorization: Bearer [INSERT TOKEN HERE]" http://localhost:8080
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestOauthTestSuite(t *testing.T) {
|
func TestOauthTestSuite(t *testing.T) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue