|
|
@ -2,6 +2,7 @@ package authmethodupdate
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"encoding/json"
|
|
|
|
|
|
|
|
"io"
|
|
|
|
"io/ioutil"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"path/filepath"
|
|
|
@ -743,6 +744,138 @@ func TestAuthMethodUpdateCommand_k8s_noMerge(t *testing.T) {
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestAuthMethodUpdateCommand_config(t *testing.T) {
|
|
|
|
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
testDir := testutil.TempDir(t, "auth-method")
|
|
|
|
|
|
|
|
defer os.RemoveAll(testDir)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
a := agent.NewTestAgent(t, `
|
|
|
|
|
|
|
|
primary_datacenter = "dc1"
|
|
|
|
|
|
|
|
acl {
|
|
|
|
|
|
|
|
enabled = true
|
|
|
|
|
|
|
|
tokens {
|
|
|
|
|
|
|
|
master = "root"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}`)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
defer a.Shutdown()
|
|
|
|
|
|
|
|
testrpc.WaitForLeader(t, a.RPC, "dc1")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
client := a.Client()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
createAuthMethod := func(t *testing.T) string {
|
|
|
|
|
|
|
|
id, err := uuid.GenerateUUID()
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
methodName := "test" + id
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_, _, err = client.ACL().AuthMethodCreate(
|
|
|
|
|
|
|
|
&api.ACLAuthMethod{
|
|
|
|
|
|
|
|
Name: methodName,
|
|
|
|
|
|
|
|
Type: "testing",
|
|
|
|
|
|
|
|
Description: "test",
|
|
|
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
|
|
|
|
"SessionID": "big",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
&api.WriteOptions{Token: "root"},
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return methodName
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
readUpdate := func(t *testing.T, methodName string) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
method, _, err := client.ACL().AuthMethodRead(
|
|
|
|
|
|
|
|
methodName,
|
|
|
|
|
|
|
|
&api.QueryOptions{Token: "root"},
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.NotNil(t, method)
|
|
|
|
|
|
|
|
require.Equal(t, "update", method.Config["SessionID"])
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
t.Run("config file", func(t *testing.T) {
|
|
|
|
|
|
|
|
methodName := createAuthMethod(t)
|
|
|
|
|
|
|
|
configFile := filepath.Join(testDir, "config.json")
|
|
|
|
|
|
|
|
jsonConfig := `{"SessionID":"update"}`
|
|
|
|
|
|
|
|
require.NoError(t, ioutil.WriteFile(configFile, []byte(jsonConfig), 0644))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
args := []string{
|
|
|
|
|
|
|
|
"-http-addr=" + a.HTTPAddr(),
|
|
|
|
|
|
|
|
"-token=root",
|
|
|
|
|
|
|
|
"-name=" + methodName,
|
|
|
|
|
|
|
|
"-no-merge=true",
|
|
|
|
|
|
|
|
"-config=@" + configFile,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ui := cli.NewMockUi()
|
|
|
|
|
|
|
|
cmd := New(ui)
|
|
|
|
|
|
|
|
code := cmd.Run(args)
|
|
|
|
|
|
|
|
require.Equal(t, 0, code)
|
|
|
|
|
|
|
|
require.Empty(t, ui.ErrorWriter.String())
|
|
|
|
|
|
|
|
readUpdate(t, methodName)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
t.Run("config stdin", func(t *testing.T) {
|
|
|
|
|
|
|
|
methodName := createAuthMethod(t)
|
|
|
|
|
|
|
|
ui := cli.NewMockUi()
|
|
|
|
|
|
|
|
cmd := New(ui)
|
|
|
|
|
|
|
|
stdinR, stdinW := io.Pipe()
|
|
|
|
|
|
|
|
cmd.testStdin = stdinR
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
|
|
|
|
stdinW.Write([]byte(`{"SessionID":"update"}`))
|
|
|
|
|
|
|
|
stdinW.Close()
|
|
|
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
args := []string{
|
|
|
|
|
|
|
|
"-http-addr=" + a.HTTPAddr(),
|
|
|
|
|
|
|
|
"-token=root",
|
|
|
|
|
|
|
|
"-name=" + methodName,
|
|
|
|
|
|
|
|
"-no-merge=true",
|
|
|
|
|
|
|
|
"-config=-",
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
code := cmd.Run(args)
|
|
|
|
|
|
|
|
require.Equal(t, 0, code)
|
|
|
|
|
|
|
|
require.Empty(t, ui.ErrorWriter.String())
|
|
|
|
|
|
|
|
readUpdate(t, methodName)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
t.Run("config string", func(t *testing.T) {
|
|
|
|
|
|
|
|
methodName := createAuthMethod(t)
|
|
|
|
|
|
|
|
args := []string{
|
|
|
|
|
|
|
|
"-http-addr=" + a.HTTPAddr(),
|
|
|
|
|
|
|
|
"-token=root",
|
|
|
|
|
|
|
|
"-name=" + methodName,
|
|
|
|
|
|
|
|
"-no-merge=true",
|
|
|
|
|
|
|
|
"-config=" + `{"SessionID":"update"}`,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ui := cli.NewMockUi()
|
|
|
|
|
|
|
|
cmd := New(ui)
|
|
|
|
|
|
|
|
code := cmd.Run(args)
|
|
|
|
|
|
|
|
require.Equal(t, 0, code)
|
|
|
|
|
|
|
|
require.Empty(t, ui.ErrorWriter.String())
|
|
|
|
|
|
|
|
readUpdate(t, methodName)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("config with no merge", func(t *testing.T) {
|
|
|
|
|
|
|
|
methodName := createAuthMethod(t)
|
|
|
|
|
|
|
|
args := []string{
|
|
|
|
|
|
|
|
"-http-addr=" + a.HTTPAddr(),
|
|
|
|
|
|
|
|
"-token=root",
|
|
|
|
|
|
|
|
"-name=" + methodName,
|
|
|
|
|
|
|
|
"-no-merge=false",
|
|
|
|
|
|
|
|
"-config=" + `{"SessionID":"update"}`,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ui := cli.NewMockUi()
|
|
|
|
|
|
|
|
cmd := New(ui)
|
|
|
|
|
|
|
|
code := cmd.Run(args)
|
|
|
|
|
|
|
|
require.Equal(t, 0, code)
|
|
|
|
|
|
|
|
require.Empty(t, ui.ErrorWriter.String())
|
|
|
|
|
|
|
|
readUpdate(t, methodName)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func getTestMethod(t *testing.T, client *api.Client, methodName string) *api.ACLAuthMethod {
|
|
|
|
func getTestMethod(t *testing.T, client *api.Client, methodName string) *api.ACLAuthMethod {
|
|
|
|
t.Helper()
|
|
|
|
t.Helper()
|
|
|
|
|
|
|
|
|
|
|
@ -766,4 +899,5 @@ func getTestName(t *testing.T) string {
|
|
|
|
id, err := uuid.GenerateUUID()
|
|
|
|
id, err := uuid.GenerateUUID()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, err)
|
|
|
|
return "test-" + id
|
|
|
|
return "test-" + id
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|