2015-12-29 05:25:11 +05:30
|
|
|
package functional
|
|
|
|
|
|
|
|
import (
|
2016-01-19 22:29:34 +05:30
|
|
|
"bytes"
|
|
|
|
"io"
|
2015-12-29 05:25:11 +05:30
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
var connConfigExample = []byte(`[
|
|
|
|
{
|
|
|
|
"type": "local",
|
|
|
|
"id": "local",
|
|
|
|
"passwordInfos": [
|
|
|
|
{
|
|
|
|
"userId":"elroy-id",
|
|
|
|
"passwordPlaintext": "bones"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"userId":"penny",
|
|
|
|
"passwordPlaintext": "kibble"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]`)
|
|
|
|
|
|
|
|
func TestDexctlCommands(t *testing.T) {
|
|
|
|
tempFile, err := ioutil.TempFile("", "dexctl_functional_tests_")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
connConfig := tempFile.Name()
|
|
|
|
defer os.Remove(connConfig)
|
|
|
|
if _, err := tempFile.Write(connConfigExample); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
tempFile.Close()
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
args []string
|
|
|
|
env []string
|
|
|
|
expErr bool
|
2016-01-19 22:29:34 +05:30
|
|
|
stdin io.Reader
|
2015-12-29 05:25:11 +05:30
|
|
|
}{
|
|
|
|
{
|
|
|
|
args: []string{"new-client", "https://example.com/callback"},
|
|
|
|
env: []string{"DEXCTL_DB_URL=" + dsn},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
args: []string{"new-client", "--db-url", dsn, "https://example.com/callback"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
args: []string{"set-connector-configs", connConfig},
|
|
|
|
env: []string{"DEXCTL_DB_URL=" + dsn},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
args: []string{"set-connector-configs", "--db-url", dsn, connConfig},
|
|
|
|
},
|
2016-01-19 22:29:34 +05:30
|
|
|
{
|
|
|
|
args: []string{"set-connector-configs", "--db-url", dsn, "-"},
|
|
|
|
stdin: bytes.NewReader(connConfigExample),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
args: []string{"set-connector-configs", "-"},
|
|
|
|
env: []string{"DEXCTL_DB_URL=" + dsn},
|
|
|
|
stdin: bytes.NewReader(connConfigExample),
|
|
|
|
},
|
2015-12-29 05:25:11 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
cmd := exec.Command("../bin/dexctl", tt.args...)
|
2016-01-19 22:29:34 +05:30
|
|
|
cmd.Stdin = tt.stdin
|
2015-12-29 05:25:11 +05:30
|
|
|
cmd.Env = tt.env
|
|
|
|
out, err := cmd.CombinedOutput()
|
|
|
|
if !tt.expErr && err != nil {
|
|
|
|
t.Errorf("cmd 'dexctl %s' failed: %v %s", strings.Join(tt.args, " "), err, out)
|
|
|
|
} else if tt.expErr && err == nil {
|
|
|
|
t.Errorf("expected cmd 'dexctl %s' to fail", strings.Join(tt.args, " "))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|