2019-01-24 16:26:36 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2019-01-08 14:54:35 +00:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
package consoleql_test
|
2019-01-08 14:54:35 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/graphql-go/graphql"
|
|
|
|
"github.com/skyrings/skyring-common/tools/uuid"
|
|
|
|
"github.com/stretchr/testify/assert"
|
2019-01-31 13:01:13 +00:00
|
|
|
"go.uber.org/zap/zaptest"
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-03-02 15:22:20 +00:00
|
|
|
"storj.io/storj/internal/post"
|
2019-01-08 14:54:35 +00:00
|
|
|
"storj.io/storj/internal/testcontext"
|
|
|
|
"storj.io/storj/pkg/auth"
|
2019-01-24 16:26:36 +00:00
|
|
|
"storj.io/storj/satellite"
|
2019-01-15 13:03:24 +00:00
|
|
|
"storj.io/storj/satellite/console"
|
|
|
|
"storj.io/storj/satellite/console/consoleauth"
|
2019-01-24 16:26:36 +00:00
|
|
|
"storj.io/storj/satellite/console/consoleweb/consoleql"
|
2019-03-02 15:22:20 +00:00
|
|
|
"storj.io/storj/satellite/mailservice"
|
2019-01-24 16:26:36 +00:00
|
|
|
"storj.io/storj/satellite/satellitedb/satellitedbtest"
|
2019-01-08 14:54:35 +00:00
|
|
|
)
|
|
|
|
|
2019-03-02 15:22:20 +00:00
|
|
|
// discardSender discard sending of an actual email
|
|
|
|
type discardSender struct{}
|
|
|
|
|
|
|
|
// SendEmail immediately returns with nil error
|
|
|
|
func (*discardSender) SendEmail(msg *post.Message) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// FromAddress returns empty post.Address
|
|
|
|
func (*discardSender) FromAddress() post.Address {
|
|
|
|
return post.Address{}
|
|
|
|
}
|
|
|
|
|
2019-01-08 14:54:35 +00:00
|
|
|
func TestGrapqhlMutation(t *testing.T) {
|
2019-01-24 16:26:36 +00:00
|
|
|
satellitedbtest.Run(t, func(t *testing.T, db satellite.DB) {
|
|
|
|
ctx := testcontext.New(t)
|
|
|
|
defer ctx.Cleanup()
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-31 13:01:13 +00:00
|
|
|
log := zaptest.NewLogger(t)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
service, err := console.NewService(
|
|
|
|
log,
|
|
|
|
&consoleauth.Hmac{Secret: []byte("my-suppa-secret-key")},
|
|
|
|
db.Console(),
|
2019-02-05 17:31:53 +00:00
|
|
|
console.TestPasswordCost,
|
2019-01-08 14:54:35 +00:00
|
|
|
)
|
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-03-02 15:22:20 +00:00
|
|
|
mailService, err := mailservice.New(log, &discardSender{}, "testdata")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
rootObject := make(map[string]interface{})
|
|
|
|
rootObject["origin"] = "http://doesntmatter.com/"
|
|
|
|
rootObject[consoleql.ActivationPath] = "?activationToken="
|
2019-03-26 15:56:16 +00:00
|
|
|
rootObject[consoleql.SignInPath] = "login"
|
2019-03-02 15:22:20 +00:00
|
|
|
|
2019-03-26 15:56:16 +00:00
|
|
|
schema, err := consoleql.CreateSchema(log, service, mailService)
|
2019-01-24 16:26:36 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
2019-01-08 14:54:35 +00:00
|
|
|
}
|
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
createUser := console.CreateUser{
|
|
|
|
UserInfo: console.UserInfo{
|
2019-03-27 12:33:32 +00:00
|
|
|
FullName: "John Roll",
|
|
|
|
ShortName: "Roll",
|
2019-01-24 16:26:36 +00:00
|
|
|
Email: "test@email.com",
|
|
|
|
},
|
|
|
|
Password: "123a123",
|
2019-01-08 14:54:35 +00:00
|
|
|
}
|
|
|
|
|
2019-03-19 17:55:43 +00:00
|
|
|
regToken, err := service.CreateRegToken(ctx, 1)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
rootUser, err := service.CreateUser(ctx, createUser, regToken.Secret)
|
2019-01-24 16:26:36 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-03-08 14:01:11 +00:00
|
|
|
activationToken, err := service.GenerateActivationToken(ctx, rootUser.ID, rootUser.Email)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2019-01-30 15:04:40 +00:00
|
|
|
|
2019-03-08 14:01:11 +00:00
|
|
|
err = service.ActivateAccount(ctx, activationToken)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2019-01-30 15:04:40 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
token, err := service.Token(ctx, createUser.Email, createUser.Password)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
sauth, err := service.Authorize(auth.WithAPIKey(ctx, []byte(token)))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
authCtx := console.WithAuth(ctx, sauth)
|
|
|
|
|
|
|
|
t.Run("Create user mutation", func(t *testing.T) {
|
|
|
|
newUser := console.CreateUser{
|
|
|
|
UserInfo: console.UserInfo{
|
2019-03-27 12:33:32 +00:00
|
|
|
FullName: "Green Mickey",
|
|
|
|
ShortName: "Green",
|
2019-01-24 16:26:36 +00:00
|
|
|
Email: "u1@email.com",
|
|
|
|
},
|
|
|
|
Password: "123a123",
|
|
|
|
}
|
|
|
|
|
2019-03-19 17:55:43 +00:00
|
|
|
regTokenTest, err := service.CreateRegToken(ctx, 1)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
query := fmt.Sprintf(
|
2019-03-27 12:33:32 +00:00
|
|
|
"mutation {createUser(input:{email:\"%s\",password:\"%s\", fullName:\"%s\", shortName:\"%s\"}, secret: \"%s\"){id,shortName,fullName,email,createdAt}}",
|
2019-01-24 16:26:36 +00:00
|
|
|
newUser.Email,
|
|
|
|
newUser.Password,
|
2019-03-27 12:33:32 +00:00
|
|
|
newUser.FullName,
|
|
|
|
newUser.ShortName,
|
2019-03-19 17:55:43 +00:00
|
|
|
regTokenTest.Secret,
|
2019-01-24 16:26:36 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
result := graphql.Do(graphql.Params{
|
|
|
|
Schema: schema,
|
|
|
|
Context: ctx,
|
|
|
|
RequestString: query,
|
2019-03-02 15:22:20 +00:00
|
|
|
RootObject: rootObject,
|
2019-01-24 16:26:36 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
for _, err := range result.Errors {
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if result.HasErrors() {
|
|
|
|
t.Fatal()
|
|
|
|
}
|
|
|
|
|
|
|
|
data := result.Data.(map[string]interface{})
|
2019-02-11 10:33:56 +00:00
|
|
|
usrData := data[consoleql.CreateUserMutation].(map[string]interface{})
|
|
|
|
idStr := usrData["id"].(string)
|
2019-01-24 16:26:36 +00:00
|
|
|
|
2019-02-11 10:33:56 +00:00
|
|
|
uID, err := uuid.Parse(idStr)
|
2019-01-24 16:26:36 +00:00
|
|
|
assert.NoError(t, err)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
user, err := service.GetUser(authCtx, *uID)
|
|
|
|
assert.NoError(t, err)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-03-27 12:33:32 +00:00
|
|
|
assert.Equal(t, newUser.FullName, user.FullName)
|
|
|
|
assert.Equal(t, newUser.ShortName, user.ShortName)
|
2019-01-08 14:54:35 +00:00
|
|
|
})
|
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
testQuery := func(t *testing.T, query string) interface{} {
|
|
|
|
result := graphql.Do(graphql.Params{
|
|
|
|
Schema: schema,
|
|
|
|
Context: authCtx,
|
|
|
|
RequestString: query,
|
2019-03-02 15:22:20 +00:00
|
|
|
RootObject: rootObject,
|
2019-01-24 16:26:36 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
for _, err := range result.Errors {
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
if result.HasErrors() {
|
|
|
|
t.Fatal()
|
|
|
|
}
|
|
|
|
|
|
|
|
return result.Data
|
2019-01-08 14:54:35 +00:00
|
|
|
}
|
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
t.Run("Update account mutation email only", func(t *testing.T) {
|
|
|
|
email := "new@email.com"
|
|
|
|
query := fmt.Sprintf(
|
2019-03-27 12:33:32 +00:00
|
|
|
"mutation {updateAccount(input:{email:\"%s\"}){id,email,fullName,shortName,createdAt}}",
|
2019-01-24 16:26:36 +00:00
|
|
|
email,
|
|
|
|
)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
result := testQuery(t, query)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
data := result.(map[string]interface{})
|
|
|
|
user := data[consoleql.UpdateAccountMutation].(map[string]interface{})
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
assert.Equal(t, rootUser.ID.String(), user[consoleql.FieldID])
|
|
|
|
assert.Equal(t, email, user[consoleql.FieldEmail])
|
2019-03-27 12:33:32 +00:00
|
|
|
assert.Equal(t, rootUser.FullName, user[consoleql.FieldFullName])
|
|
|
|
assert.Equal(t, rootUser.ShortName, user[consoleql.FieldShortName])
|
2019-01-24 16:26:36 +00:00
|
|
|
})
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-03-27 12:33:32 +00:00
|
|
|
t.Run("Update account mutation fullName only", func(t *testing.T) {
|
|
|
|
fullName := "George"
|
2019-01-24 16:26:36 +00:00
|
|
|
query := fmt.Sprintf(
|
2019-03-27 12:33:32 +00:00
|
|
|
"mutation {updateAccount(input:{fullName:\"%s\"}){id,email,fullName,shortName,createdAt}}",
|
|
|
|
fullName,
|
2019-01-24 16:26:36 +00:00
|
|
|
)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
result := testQuery(t, query)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
data := result.(map[string]interface{})
|
|
|
|
user := data[consoleql.UpdateAccountMutation].(map[string]interface{})
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
assert.Equal(t, rootUser.ID.String(), user[consoleql.FieldID])
|
|
|
|
assert.Equal(t, rootUser.Email, user[consoleql.FieldEmail])
|
2019-03-27 12:33:32 +00:00
|
|
|
assert.Equal(t, fullName, user[consoleql.FieldFullName])
|
|
|
|
assert.Equal(t, rootUser.ShortName, user[consoleql.FieldShortName])
|
2019-01-24 16:26:36 +00:00
|
|
|
})
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-03-27 12:33:32 +00:00
|
|
|
t.Run("Update account mutation shortName only", func(t *testing.T) {
|
|
|
|
shortName := "Yellow"
|
2019-01-24 16:26:36 +00:00
|
|
|
query := fmt.Sprintf(
|
2019-03-27 12:33:32 +00:00
|
|
|
"mutation {updateAccount(input:{shortName:\"%s\"}){id,email,fullName,shortName,createdAt}}",
|
|
|
|
shortName,
|
2019-01-24 16:26:36 +00:00
|
|
|
)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
result := testQuery(t, query)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
data := result.(map[string]interface{})
|
|
|
|
user := data[consoleql.UpdateAccountMutation].(map[string]interface{})
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
assert.Equal(t, rootUser.ID.String(), user[consoleql.FieldID])
|
|
|
|
assert.Equal(t, rootUser.Email, user[consoleql.FieldEmail])
|
2019-03-27 12:33:32 +00:00
|
|
|
assert.Equal(t, rootUser.FullName, user[consoleql.FieldFullName])
|
|
|
|
assert.Equal(t, shortName, user[consoleql.FieldShortName])
|
2019-01-24 16:26:36 +00:00
|
|
|
})
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
t.Run("Update account mutation all info", func(t *testing.T) {
|
|
|
|
email := "test@newmail.com"
|
2019-03-27 12:33:32 +00:00
|
|
|
fullName := "Fill Goal"
|
|
|
|
shortName := "Goal"
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
query := fmt.Sprintf(
|
2019-03-27 12:33:32 +00:00
|
|
|
"mutation {updateAccount(input:{email:\"%s\",fullName:\"%s\",shortName:\"%s\"}){id,email,fullName,shortName,createdAt}}",
|
2019-01-24 16:26:36 +00:00
|
|
|
email,
|
2019-03-27 12:33:32 +00:00
|
|
|
fullName,
|
|
|
|
shortName,
|
2019-01-24 16:26:36 +00:00
|
|
|
)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
result := testQuery(t, query)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
data := result.(map[string]interface{})
|
|
|
|
user := data[consoleql.UpdateAccountMutation].(map[string]interface{})
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
assert.Equal(t, rootUser.ID.String(), user[consoleql.FieldID])
|
|
|
|
assert.Equal(t, email, user[consoleql.FieldEmail])
|
2019-03-27 12:33:32 +00:00
|
|
|
assert.Equal(t, fullName, user[consoleql.FieldFullName])
|
|
|
|
assert.Equal(t, shortName, user[consoleql.FieldShortName])
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
createdAt := time.Time{}
|
|
|
|
err := createdAt.UnmarshalText([]byte(user[consoleql.FieldCreatedAt].(string)))
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
assert.NoError(t, err)
|
2019-02-06 14:48:30 +00:00
|
|
|
assert.True(t, rootUser.CreatedAt.Equal(createdAt))
|
2019-01-24 16:26:36 +00:00
|
|
|
})
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
t.Run("Change password mutation", func(t *testing.T) {
|
|
|
|
newPassword := "145a145a"
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
query := fmt.Sprintf(
|
2019-03-27 12:33:32 +00:00
|
|
|
"mutation {changePassword(password:\"%s\",newPassword:\"%s\"){id,email,fullName,shortName,createdAt}}",
|
2019-01-24 16:26:36 +00:00
|
|
|
createUser.Password,
|
|
|
|
newPassword,
|
|
|
|
)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
result := testQuery(t, query)
|
|
|
|
|
|
|
|
data := result.(map[string]interface{})
|
|
|
|
user := data[consoleql.ChangePasswordMutation].(map[string]interface{})
|
|
|
|
|
|
|
|
assert.Equal(t, rootUser.ID.String(), user[consoleql.FieldID])
|
|
|
|
assert.Equal(t, rootUser.Email, user[consoleql.FieldEmail])
|
2019-03-27 12:33:32 +00:00
|
|
|
assert.Equal(t, rootUser.FullName, user[consoleql.FieldFullName])
|
|
|
|
assert.Equal(t, rootUser.ShortName, user[consoleql.FieldShortName])
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
createdAt := time.Time{}
|
|
|
|
err := createdAt.UnmarshalText([]byte(user[consoleql.FieldCreatedAt].(string)))
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
assert.NoError(t, err)
|
2019-02-06 14:48:30 +00:00
|
|
|
assert.True(t, rootUser.CreatedAt.Equal(createdAt))
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
oldHash := rootUser.PasswordHash
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
rootUser, err = service.GetUser(authCtx, rootUser.ID)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
assert.False(t, bytes.Equal(oldHash, rootUser.PasswordHash))
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
createUser.Password = newPassword
|
|
|
|
})
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
token, err = service.Token(ctx, rootUser.Email, createUser.Password)
|
2019-01-08 14:54:35 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
sauth, err = service.Authorize(auth.WithAPIKey(ctx, []byte(token)))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
authCtx = console.WithAuth(ctx, sauth)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
var projectID string
|
|
|
|
t.Run("Create project mutation", func(t *testing.T) {
|
|
|
|
projectInfo := console.ProjectInfo{
|
|
|
|
Name: "Project name",
|
|
|
|
Description: "desc",
|
|
|
|
}
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
query := fmt.Sprintf(
|
2019-01-28 18:20:33 +00:00
|
|
|
"mutation {createProject(input:{name:\"%s\",description:\"%s\"}){name,description,id,createdAt}}",
|
2019-01-24 16:26:36 +00:00
|
|
|
projectInfo.Name,
|
|
|
|
projectInfo.Description,
|
|
|
|
)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
result := testQuery(t, query)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
data := result.(map[string]interface{})
|
|
|
|
project := data[consoleql.CreateProjectMutation].(map[string]interface{})
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
assert.Equal(t, projectInfo.Name, project[consoleql.FieldName])
|
|
|
|
assert.Equal(t, projectInfo.Description, project[consoleql.FieldDescription])
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
projectID = project[consoleql.FieldID].(string)
|
|
|
|
})
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
pID, err := uuid.Parse(projectID)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
project, err := service.GetProject(authCtx, *pID)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err, project)
|
|
|
|
}
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
t.Run("Update project description mutation", func(t *testing.T) {
|
|
|
|
query := fmt.Sprintf(
|
|
|
|
"mutation {updateProjectDescription(id:\"%s\",description:\"%s\"){id,name,description}}",
|
|
|
|
project.ID.String(),
|
|
|
|
"",
|
|
|
|
)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
result := testQuery(t, query)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
data := result.(map[string]interface{})
|
|
|
|
proj := data[consoleql.UpdateProjectDescriptionMutation].(map[string]interface{})
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
assert.Equal(t, project.ID.String(), proj[consoleql.FieldID])
|
|
|
|
assert.Equal(t, project.Name, proj[consoleql.FieldName])
|
|
|
|
assert.Equal(t, "", proj[consoleql.FieldDescription])
|
|
|
|
})
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-03-19 17:55:43 +00:00
|
|
|
regTokenUser1, err := service.CreateRegToken(ctx, 1)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
user1, err := service.CreateUser(authCtx, console.CreateUser{
|
|
|
|
UserInfo: console.UserInfo{
|
2019-03-27 12:33:32 +00:00
|
|
|
FullName: "User1",
|
|
|
|
Email: "u1@email.net",
|
2019-01-24 16:26:36 +00:00
|
|
|
},
|
|
|
|
Password: "123a123",
|
2019-03-19 17:55:43 +00:00
|
|
|
}, regTokenUser1.Secret)
|
2019-01-30 15:04:40 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err, project)
|
|
|
|
}
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-02-05 17:22:17 +00:00
|
|
|
t.Run("Activation", func(t *testing.T) {
|
|
|
|
activationToken1, err := service.GenerateActivationToken(
|
|
|
|
ctx,
|
|
|
|
user1.ID,
|
|
|
|
"u1@email.net",
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err, project)
|
|
|
|
}
|
2019-03-08 14:01:11 +00:00
|
|
|
err = service.ActivateAccount(ctx, activationToken1)
|
2019-02-05 17:22:17 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err, project)
|
|
|
|
}
|
|
|
|
user1.Email = "u1@email.net"
|
|
|
|
})
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-03-19 17:55:43 +00:00
|
|
|
regTokenUser2, err := service.CreateRegToken(ctx, 1)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
user2, err := service.CreateUser(authCtx, console.CreateUser{
|
|
|
|
UserInfo: console.UserInfo{
|
2019-03-27 12:33:32 +00:00
|
|
|
FullName: "User1",
|
|
|
|
Email: "u2@email.net",
|
2019-01-24 16:26:36 +00:00
|
|
|
},
|
|
|
|
Password: "123a123",
|
2019-03-19 17:55:43 +00:00
|
|
|
}, regTokenUser2.Secret)
|
2019-02-05 17:22:17 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err, project)
|
|
|
|
}
|
2019-02-05 17:22:17 +00:00
|
|
|
|
|
|
|
t.Run("Activation", func(t *testing.T) {
|
|
|
|
activationToken2, err := service.GenerateActivationToken(
|
|
|
|
ctx,
|
|
|
|
user2.ID,
|
|
|
|
"u2@email.net",
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err, project)
|
|
|
|
}
|
2019-03-08 14:01:11 +00:00
|
|
|
err = service.ActivateAccount(ctx, activationToken2)
|
2019-02-05 17:22:17 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err, project)
|
|
|
|
}
|
|
|
|
user2.Email = "u2@email.net"
|
|
|
|
})
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
t.Run("Add project members mutation", func(t *testing.T) {
|
|
|
|
query := fmt.Sprintf(
|
|
|
|
"mutation {addProjectMembers(projectID:\"%s\",email:[\"%s\",\"%s\"]){id,name,members(limit:50,offset:0){joinedAt}}}",
|
|
|
|
project.ID.String(),
|
|
|
|
user1.Email,
|
|
|
|
user2.Email,
|
|
|
|
)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
result := testQuery(t, query)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
data := result.(map[string]interface{})
|
|
|
|
proj := data[consoleql.AddProjectMembersMutation].(map[string]interface{})
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
assert.Equal(t, project.ID.String(), proj[consoleql.FieldID])
|
|
|
|
assert.Equal(t, project.Name, proj[consoleql.FieldName])
|
|
|
|
assert.Equal(t, 3, len(proj[consoleql.FieldMembers].([]interface{})))
|
|
|
|
})
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
t.Run("Delete project members mutation", func(t *testing.T) {
|
|
|
|
query := fmt.Sprintf(
|
|
|
|
"mutation {deleteProjectMembers(projectID:\"%s\",email:[\"%s\",\"%s\"]){id,name,members(limit:50,offset:0){user{id}}}}",
|
|
|
|
project.ID.String(),
|
|
|
|
user1.Email,
|
|
|
|
user2.Email,
|
|
|
|
)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
result := testQuery(t, query)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
data := result.(map[string]interface{})
|
|
|
|
proj := data[consoleql.DeleteProjectMembersMutation].(map[string]interface{})
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
members := proj[consoleql.FieldMembers].([]interface{})
|
|
|
|
rootMember := members[0].(map[string]interface{})[consoleql.UserType].(map[string]interface{})
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
assert.Equal(t, project.ID.String(), proj[consoleql.FieldID])
|
|
|
|
assert.Equal(t, project.Name, proj[consoleql.FieldName])
|
|
|
|
assert.Equal(t, 1, len(members))
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
assert.Equal(t, rootUser.ID.String(), rootMember[consoleql.FieldID])
|
|
|
|
})
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
var keyID string
|
|
|
|
t.Run("Create api key mutation", func(t *testing.T) {
|
|
|
|
keyName := "key1"
|
|
|
|
query := fmt.Sprintf(
|
|
|
|
"mutation {createAPIKey(projectID:\"%s\",name:\"%s\"){key,keyInfo{id,name,projectID}}}",
|
|
|
|
project.ID.String(),
|
|
|
|
keyName,
|
|
|
|
)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
result := testQuery(t, query)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
data := result.(map[string]interface{})
|
|
|
|
createAPIKey := data[consoleql.CreateAPIKeyMutation].(map[string]interface{})
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
key := createAPIKey[consoleql.FieldKey].(string)
|
|
|
|
keyInfo := createAPIKey[consoleql.APIKeyInfoType].(map[string]interface{})
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
assert.NotEqual(t, "", key)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
assert.Equal(t, keyName, keyInfo[consoleql.FieldName])
|
|
|
|
assert.Equal(t, project.ID.String(), keyInfo[consoleql.FieldProjectID])
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
keyID = keyInfo[consoleql.FieldID].(string)
|
|
|
|
})
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
t.Run("Delete api key mutation", func(t *testing.T) {
|
|
|
|
id, err := uuid.Parse(keyID)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
info, err := service.GetAPIKeyInfo(authCtx, *id)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
query := fmt.Sprintf(
|
2019-02-13 11:34:40 +00:00
|
|
|
"mutation {deleteAPIKeys(id:[\"%s\"]){name,projectID}}",
|
|
|
|
keyID,
|
2019-01-24 16:26:36 +00:00
|
|
|
)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
result := testQuery(t, query)
|
|
|
|
data := result.(map[string]interface{})
|
2019-02-13 11:34:40 +00:00
|
|
|
keyInfoList := data[consoleql.DeleteAPIKeysMutation].([]interface{})
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-02-13 11:34:40 +00:00
|
|
|
for _, k := range keyInfoList {
|
|
|
|
keyInfo := k.(map[string]interface{})
|
|
|
|
|
|
|
|
assert.Equal(t, info.Name, keyInfo[consoleql.FieldName])
|
|
|
|
assert.Equal(t, project.ID.String(), keyInfo[consoleql.FieldProjectID])
|
|
|
|
}
|
2019-01-24 16:26:36 +00:00
|
|
|
})
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
t.Run("Delete project mutation", func(t *testing.T) {
|
|
|
|
query := fmt.Sprintf(
|
|
|
|
"mutation {deleteProject(id:\"%s\"){id,name}}",
|
|
|
|
projectID,
|
|
|
|
)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
result := testQuery(t, query)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
data := result.(map[string]interface{})
|
|
|
|
proj := data[consoleql.DeleteProjectMutation].(map[string]interface{})
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
assert.Equal(t, project.Name, proj[consoleql.FieldName])
|
|
|
|
assert.Equal(t, project.ID.String(), proj[consoleql.FieldID])
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
_, err := service.GetProject(authCtx, project.ID)
|
|
|
|
assert.Error(t, err)
|
|
|
|
})
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
t.Run("Delete account mutation", func(t *testing.T) {
|
|
|
|
query := fmt.Sprintf(
|
|
|
|
"mutation {deleteAccount(password:\"%s\"){id}}",
|
|
|
|
createUser.Password,
|
|
|
|
)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
result := testQuery(t, query)
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
data := result.(map[string]interface{})
|
|
|
|
user := data[consoleql.DeleteAccountMutation].(map[string]interface{})
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
assert.Equal(t, rootUser.ID.String(), user[consoleql.FieldID])
|
2019-01-08 14:54:35 +00:00
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
_, err := service.GetUser(authCtx, rootUser.ID)
|
|
|
|
assert.Error(t, err)
|
|
|
|
})
|
2019-01-08 14:54:35 +00:00
|
|
|
})
|
|
|
|
}
|