2020-08-12 00:40:39 -04:00
|
|
|
package controller_test
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/hashicorp/boundary/api/authmethods"
|
|
|
|
|
"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)
|
2020-08-25 00:21:08 -04:00
|
|
|
amId := "ampw_1234567890"
|
2020-08-12 00:40:39 -04:00
|
|
|
user := "user"
|
|
|
|
|
password := "passpass"
|
|
|
|
|
logger := hclog.New(&hclog.LoggerOptions{
|
|
|
|
|
Level: hclog.Trace,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
c1 := controller.NewTestController(t, &controller.TestControllerOpts{
|
|
|
|
|
DefaultAuthMethodId: amId,
|
|
|
|
|
DefaultLoginName: user,
|
|
|
|
|
DefaultPassword: password,
|
|
|
|
|
Logger: logger.Named("c1"),
|
|
|
|
|
})
|
|
|
|
|
defer c1.Shutdown()
|
|
|
|
|
|
|
|
|
|
c2 := c1.AddClusterControllerMember(t, &controller.TestControllerOpts{
|
|
|
|
|
Logger: logger.Named("c2"),
|
|
|
|
|
})
|
|
|
|
|
defer c2.Shutdown()
|
|
|
|
|
|
2020-08-27 20:43:33 -04:00
|
|
|
auth := authmethods.NewClient(c1.Client())
|
2020-08-12 00:40:39 -04:00
|
|
|
token1, apiErr, err := auth.Authenticate(c1.Context(), amId, user, password)
|
|
|
|
|
require.Nil(err)
|
|
|
|
|
require.Nil(apiErr)
|
|
|
|
|
require.NotNil(token1)
|
|
|
|
|
|
|
|
|
|
time.Sleep(5 * time.Second)
|
2020-08-27 20:43:33 -04:00
|
|
|
auth = authmethods.NewClient(c2.Client())
|
2020-08-12 00:40:39 -04:00
|
|
|
token2, apiErr, err := auth.Authenticate(c2.Context(), amId, user, password)
|
|
|
|
|
require.Nil(err)
|
|
|
|
|
require.Nil(apiErr)
|
|
|
|
|
require.NotNil(token2)
|
|
|
|
|
|
|
|
|
|
assert.NotEqual(token1.Token, token2.Token)
|
|
|
|
|
|
|
|
|
|
c1.Client().SetToken(token1.Token)
|
2020-08-17 15:38:41 -04:00
|
|
|
c1.Client().SetScopeId(scope.Global.String())
|
2020-08-12 00:40:39 -04:00
|
|
|
c2.Client().SetToken(token1.Token) // Same token, as it should work on both
|
2020-08-17 15:38:41 -04:00
|
|
|
c2.Client().SetScopeId(scope.Global.String())
|
2020-08-12 00:40:39 -04:00
|
|
|
|
|
|
|
|
// Create a project, read from the other
|
2020-08-27 20:43:33 -04:00
|
|
|
org, apiErr, err := scopes.NewClient(c1.Client()).Create(c1.Context(), scope.Global.String())
|
2020-08-12 00:40:39 -04:00
|
|
|
require.NoError(err)
|
|
|
|
|
require.Nil(apiErr)
|
2020-08-17 15:38:41 -04:00
|
|
|
require.NotNil(org)
|
2020-08-12 00:40:39 -04:00
|
|
|
|
2020-08-27 20:43:33 -04:00
|
|
|
proj, apiErr, err := scopes.NewClient(c2.Client()).Read(c2.Context(), org.Id)
|
2020-08-12 00:40:39 -04:00
|
|
|
require.NoError(err)
|
|
|
|
|
require.Nil(apiErr)
|
|
|
|
|
require.NotNil(proj)
|
|
|
|
|
}
|