veyron/services: porting the identity server from shell to Go
This CL also replaces the use of os.Stderr in the principal tool with
os.Stdout as the identity server integration test is using the output
of the principal tool and, as a general rule, depending on error output
is brittle. In addition, our new Go-based integration test framework,
to which we are porting the identity server test, does not play nicely
with error output.
Change-Id: I38eaabea603ce2b58f82ceac105200960b0adca0
diff --git a/services/identity/identityd/identityd_v23_test.go b/services/identity/identityd/identityd_v23_test.go
new file mode 100644
index 0000000..127b20c
--- /dev/null
+++ b/services/identity/identityd/identityd_v23_test.go
@@ -0,0 +1,78 @@
+package main_test
+
+import (
+ "crypto/tls"
+ "io/ioutil"
+ "net/http"
+ "net/http/cookiejar"
+ "regexp"
+ "strings"
+
+ "v.io/core/veyron/lib/testutil/v23tests"
+)
+
+//go:generate v23 test generate .
+
+var (
+ urlRE = regexp.MustCompile("^https://")
+)
+
+func seekBlessings(i *v23tests.T, principal *v23tests.Binary) {
+ args := []string{
+ "seekblessings",
+ "--browser=false",
+ "--from=https://localhost:8125/google",
+ "-v=3",
+ }
+ inv := principal.Start(args...)
+ // Scan the output of "principal seekblessings", looking for the
+ // URL that can be used to retrieve the blessings.
+ for {
+ if line := inv.Session.ReadLine(); urlRE.MatchString(line) {
+ transport := &http.Transport{
+ TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
+ }
+ jar, err := cookiejar.New(&cookiejar.Options{})
+ if err != nil {
+ i.Fatalf("failed to create a cookie jar: %v", err)
+ }
+ client := &http.Client{
+ Jar: jar,
+ Transport: transport,
+ }
+ resp, err := client.Get(line)
+ if err != nil {
+ i.Fatalf("Get(%q) failed: %v", line, err)
+ }
+ output, err := ioutil.ReadAll(resp.Body)
+ resp.Body.Close()
+ if err != nil {
+ i.Fatalf("ReadAll() failed: %v", err)
+ }
+ if want := "Received blessings"; strings.Contains(string(output), want) {
+ i.Fatalf("failed to seek blessings: %v", string(output))
+ }
+ return
+ }
+ }
+}
+
+func V23TestIdentityServer(i *v23tests.T) {
+ v23tests.RunRootMT(i, "--veyron.tcp.address=127.0.0.1:0")
+
+ // Start the identity server.
+ args := []string{
+ "-host=localhost",
+ "-veyron.tcp.address=127.0.0.1:0",
+ }
+ i.BuildGoPkg("v.io/core/veyron/services/identity/identityd_test").Start(args...)
+
+ // Use the principal tool to seekblessings.
+ principal := i.BuildGoPkg("v.io/core/veyron/tools/principal")
+ // Test an initial seekblessings call.
+ seekBlessings(i, principal)
+ // Test that a subsequent call succeeds with the same
+ // credentials. This means that the blessings and principal from the
+ // first call works correctly.
+ seekBlessings(i, principal)
+}
diff --git a/services/identity/identityd/v23_test.go b/services/identity/identityd/v23_test.go
new file mode 100644
index 0000000..72afa15
--- /dev/null
+++ b/services/identity/identityd/v23_test.go
@@ -0,0 +1,22 @@
+// This file was auto-generated via go generate.
+// DO NOT UPDATE MANUALLY
+package main_test
+
+import "testing"
+import "os"
+
+import "v.io/core/veyron/lib/testutil"
+import "v.io/core/veyron/lib/testutil/v23tests"
+
+func TestMain(m *testing.M) {
+ testutil.Init()
+ cleanup := v23tests.UseSharedBinDir()
+ r := m.Run()
+ cleanup()
+ // TODO(cnicolaou): call modules.Dispatch and remove the need for TestHelperProcess
+ os.Exit(r)
+}
+
+func TestV23IdentityServer(t *testing.T) {
+ v23tests.RunTest(t, V23TestIdentityServer)
+}
diff --git a/services/identity/test.sh b/services/identity/test.sh
index 471e140..fc88b78 100755
--- a/services/identity/test.sh
+++ b/services/identity/test.sh
@@ -19,7 +19,7 @@
runprincipal() {
local PFILE="${WORKDIR}/principalfile"
# Start the tool in the background.
- "${PRINCIPAL_BIN}" seekblessings --browser=false --from=https://localhost:8125/google -v=3 2> "${PFILE}" &
+ "${PRINCIPAL_BIN}" seekblessings --browser=false --from=https://localhost:8125/google -v=3 > "${PFILE}" &
sleep 2
# Search for the url and run it.
cat "${PFILE}" | grep https |
diff --git a/services/mgmt/application/applicationd/applicationd_v23_test.go b/services/mgmt/application/applicationd/applicationd_v23_test.go
index e6c6a46..a3c0c16 100644
--- a/services/mgmt/application/applicationd/applicationd_v23_test.go
+++ b/services/mgmt/application/applicationd/applicationd_v23_test.go
@@ -12,11 +12,6 @@
"v.io/core/veyron2/security"
)
-var binPkgs = []string{
- "v.io/core/veyron/services/mgmt/application/applicationd",
- "v.io/core/veyron/tools/application",
-}
-
//go:generate v23 test generate
func helper(i *v23tests.T, clientBin *v23tests.Binary, expectError bool, credentials, cmd string, args ...string) string {
diff --git a/tools/principal/bless.go b/tools/principal/bless.go
index 7963762..510a538 100644
--- a/tools/principal/bless.go
+++ b/tools/principal/bless.go
@@ -78,8 +78,8 @@
if err != nil {
return nil, fmt.Errorf("failed to create seekBlessingsURL: %s", err)
}
- fmt.Fprintln(os.Stderr, "Please visit the following URL to seek blessings:")
- fmt.Fprintln(os.Stderr, url)
+ fmt.Fprintln(os.Stdout, "Please visit the following URL to seek blessings:")
+ fmt.Fprintln(os.Stdout, url)
// Make an attempt to start the browser as a convenience.
// If it fails, doesn't matter - the client can see the URL printed above.
// Use exec.Command().Start instead of exec.Command().Run since there is no
diff --git a/tools/principal/main.go b/tools/principal/main.go
index f39f63c..d7deab2 100644
--- a/tools/principal/main.go
+++ b/tools/principal/main.go
@@ -604,7 +604,8 @@
return fmt.Errorf("AddToRoots failed: %v", err)
}
}
- return dumpBlessings(blessings)
+ fmt.Fprintf(cmd.Stdout(), "Received blessings: %v", blessings)
+ return nil
},
}