Files
threshold/internal/servers/controller/multi_test.go
T

62 lines
2.1 KiB
Go
Raw Normal View History

2020-08-12 00:40:39 -04:00
package controller_test
import (
2021-04-08 20:54:32 -04:00
"encoding/json"
2020-08-12 00:40:39 -04:00
"testing"
"time"
"github.com/hashicorp/boundary/api/authmethods"
2021-04-08 20:54:32 -04:00
"github.com/hashicorp/boundary/api/authtokens"
2020-08-12 00:40:39 -04:00
"github.com/hashicorp/boundary/api/scopes"
"github.com/hashicorp/boundary/internal/servers/controller"
2020-08-17 15:38:41 -04:00
"github.com/hashicorp/boundary/internal/types/scope"
2020-08-12 00:40:39 -04:00
"github.com/hashicorp/go-hclog"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestAuthenticationMulti(t *testing.T) {
assert, require := assert.New(t), require.New(t)
logger := hclog.New(&hclog.LoggerOptions{
Level: hclog.Trace,
})
c1 := controller.NewTestController(t, &controller.TestControllerOpts{
Logger: logger.Named("c1"),
2020-08-12 00:40:39 -04:00
})
defer c1.Shutdown()
c2 := c1.AddClusterControllerMember(t, &controller.TestControllerOpts{
Logger: logger.Named("c2"),
})
defer c2.Shutdown()
auth := authmethods.NewClient(c1.Client())
2021-04-08 20:54:32 -04:00
token1Result, err := auth.Authenticate(c1.Context(), c1.Server().DevPasswordAuthMethodId, "login", map[string]interface{}{"login_name": c1.Server().DevLoginName, "password": c1.Server().DevPassword})
2020-08-12 00:40:39 -04:00
require.Nil(err)
2021-04-08 20:54:32 -04:00
token1 := new(authtokens.AuthToken)
require.NoError(json.Unmarshal(token1Result.GetRawAttributes(), token1))
2020-08-12 00:40:39 -04:00
require.NotNil(token1)
time.Sleep(5 * time.Second)
auth = authmethods.NewClient(c2.Client())
2021-04-08 20:54:32 -04:00
token2Result, err := auth.Authenticate(c2.Context(), c2.Server().DevPasswordAuthMethodId, "login", map[string]interface{}{"login_name": c2.Server().DevLoginName, "password": c2.Server().DevPassword})
2020-08-12 00:40:39 -04:00
require.Nil(err)
2021-04-08 20:54:32 -04:00
token2 := new(authtokens.AuthToken)
require.NoError(json.Unmarshal(token2Result.GetRawAttributes(), token2))
2020-08-12 00:40:39 -04:00
require.NotNil(token2)
assert.NotEqual(token1.Token, token2.Token)
c1.Client().SetToken(token1.Token)
c2.Client().SetToken(token1.Token) // Same token, as it should work on both
// Create a project, read from the other
2020-09-24 14:34:58 -07:00
org, err := scopes.NewClient(c1.Client()).Create(c1.Context(), scope.Global.String())
2020-08-12 00:40:39 -04:00
require.NoError(err)
require.NotNil(org.Item)
2020-08-12 00:40:39 -04:00
2020-09-24 14:34:58 -07:00
proj, err := scopes.NewClient(c2.Client()).Read(c2.Context(), org.Item.Id)
2020-08-12 00:40:39 -04:00
require.NoError(err)
require.NotNil(proj.Item)
2020-08-12 00:40:39 -04:00
}