veyron/services/identity: Add /blessing-root route to get the public key
and names of the identity server's blessings.
Also switch the /pubkey/ route to /pubkey, since the trailing slash was
confusing.
Change-Id: Ia0fcc4bcdbef527878221563050d9ad33ec83618
diff --git a/services/identity/handlers/handlers_test.go b/services/identity/handlers/handlers_test.go
index 09d2ec8..477761d 100644
--- a/services/identity/handlers/handlers_test.go
+++ b/services/identity/handlers/handlers_test.go
@@ -1,14 +1,18 @@
package handlers
import (
+ "encoding/base64"
+ "encoding/json"
"io/ioutil"
"net/http"
"net/http/httptest"
"reflect"
+ "sort"
"testing"
"veyron.io/veyron/veyron2/security"
+ tsecurity "veyron.io/veyron/veyron/lib/testutil/security"
vsecurity "veyron.io/veyron/veyron/security"
)
@@ -36,3 +40,40 @@
t.Errorf("Got %v, want %v", got, want)
}
}
+
+func TestBlessingRoot(t *testing.T) {
+ blessingNames := []string{"test-blessing-name-1", "test-blessing-name-2"}
+ p := tsecurity.NewPrincipal(blessingNames...)
+
+ ts := httptest.NewServer(BlessingRoot{p})
+ defer ts.Close()
+ response, err := http.Get(ts.URL)
+ if err != nil {
+ t.Fatal(err)
+ }
+ dec := json.NewDecoder(response.Body)
+ var res BlessingRootResponse
+ if err := dec.Decode(&res); err != nil {
+ t.Fatal(err)
+ }
+
+ // Check that the names are correct.
+ sort.Strings(blessingNames)
+ sort.Strings(res.Names)
+ if !reflect.DeepEqual(res.Names, blessingNames) {
+ t.Errorf("Response has incorrect name. Got %v, want %v", res.Names, blessingNames)
+ }
+
+ // Check that the public key is correct.
+ gotMarshalled, err := base64.URLEncoding.DecodeString(res.PublicKey)
+ if err != nil {
+ t.Fatal(err)
+ }
+ got, err := security.UnmarshalPublicKey(gotMarshalled)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if want := p.PublicKey(); !reflect.DeepEqual(got, want) {
+ t.Errorf("Response has incorrect public key. Got %v, want %v", got, want)
+ }
+}