Permalink
Browse files

Cosmetic Changes

 - Fixing inconsistent v2pb and keyspb.
 - Fixing inconsistent srv and svr.
 - Fixing inconsistent primary_test_email and primaryUserEmail.
 - Fixing variable naming convention inconsistencies.
  • Loading branch information...
1 parent fe0aae9 commit 85519fbfbe6a05aad0280e058282f25cb2f2efb4 @cesarghali cesarghali committed Aug 18, 2015
View
@@ -1,4 +1,6 @@
*.pb.go
*.swp
*~
+srv
+# Old binary
svr
View
@@ -11,3 +11,4 @@
Gary Belvin <gdbelvin@gmail.com>
Daniel Ziegler <dmz@yahoo-inc.com>
+Cesar Ghali <cghali@uci.edu>
View
@@ -40,7 +40,7 @@ INCLUDES+= -I=$(GOPATH)/src/
INCLUDES+= -I=$(GOPATH)/src/github.com/google/protobuf/src/ # proto descriptor
main: proto
- go build -o svr server.go
+ go build -o srv server.go
test: main
go test ./rest ./keyserver ./proxy ./merkle ./builder
@@ -23,7 +23,7 @@ import (
"google.golang.org/grpc/codes"
internalpb "github.com/google/e2e-key-server/proto/internal"
- keyspb "github.com/google/e2e-key-server/proto/v2"
+ v2pb "github.com/google/e2e-key-server/proto/v2"
context "golang.org/x/net/context"
proto3 "google/protobuf"
)
@@ -48,7 +48,7 @@ func New(storage storage.Storage, tree *merkle.Tree) *Server {
// GetUser returns a user's profile and proof that there is only one object for
// this user and that it is the same one being provided to everyone else.
// GetUser also supports querying past values by setting the epoch field.
-func (s *Server) GetUser(ctx context.Context, in *keyspb.GetUserRequest) (*keyspb.EntryProfileAndProof, error) {
+func (s *Server) GetUser(ctx context.Context, in *v2pb.GetUserRequest) (*v2pb.EntryProfileAndProof, error) {
_, index, err := s.Vuf(in.UserId)
if err != nil {
return nil, err
@@ -62,20 +62,20 @@ func (s *Server) GetUser(ctx context.Context, in *keyspb.GetUserRequest) (*keysp
// This key server doesn't employ a merkle tree yet. This is why most of
// fields in EntryProfileAndProof do not exist.
// TODO(cesarghali): integrate merkle tree.
- result := &keyspb.EntryProfileAndProof{
+ result := &v2pb.EntryProfileAndProof{
Profile: e.Profile,
}
return result, nil
}
// ListUserHistory returns a list of UserProofs covering a period of time.
-func (s *Server) ListUserHistory(ctx context.Context, in *keyspb.ListUserHistoryRequest) (*keyspb.ListUserHistoryResponse, error) {
+func (s *Server) ListUserHistory(ctx context.Context, in *v2pb.ListUserHistoryRequest) (*v2pb.ListUserHistoryResponse, error) {
return nil, grpc.Errorf(codes.Unimplemented, "Unimplemented")
}
// UpdateUser updates a user's profile. If the user does not exist, a new
// profile will be created.
-func (s *Server) UpdateUser(ctx context.Context, in *keyspb.UpdateUserRequest) (*proto3.Empty, error) {
+func (s *Server) UpdateUser(ctx context.Context, in *v2pb.UpdateUserRequest) (*proto3.Empty, error) {
if err := s.validateUpdateUserRequest(ctx, in); err != nil {
return nil, err
}
@@ -107,16 +107,16 @@ func (s *Server) UpdateUser(ctx context.Context, in *keyspb.UpdateUserRequest) (
}
// List the Signed Epoch Heads, from epoch to epoch.
-func (s *Server) ListSEH(ctx context.Context, in *keyspb.ListSEHRequest) (*keyspb.ListSEHResponse, error) {
+func (s *Server) ListSEH(ctx context.Context, in *v2pb.ListSEHRequest) (*v2pb.ListSEHResponse, error) {
return nil, grpc.Errorf(codes.Unimplemented, "Unimplemented")
}
// List the EntryUpdates by update number.
-func (s *Server) ListUpdate(ctx context.Context, in *keyspb.ListUpdateRequest) (*keyspb.ListUpdateResponse, error) {
+func (s *Server) ListUpdate(ctx context.Context, in *v2pb.ListUpdateRequest) (*v2pb.ListUpdateResponse, error) {
return nil, grpc.Errorf(codes.Unimplemented, "Unimplemented")
}
// ListSteps combines SEH and EntryUpdates into single list.
-func (s *Server) ListSteps(ctx context.Context, in *keyspb.ListStepsRequest) (*keyspb.ListStepsResponse, error) {
+func (s *Server) ListSteps(ctx context.Context, in *v2pb.ListStepsRequest) (*v2pb.ListStepsResponse, error) {
return nil, grpc.Errorf(codes.Unimplemented, "Unimplemented")
}
@@ -30,7 +30,7 @@ import (
"google.golang.org/grpc/codes"
proto "github.com/golang/protobuf/proto"
- keyspb "github.com/google/e2e-key-server/proto/v2"
+ v2pb "github.com/google/e2e-key-server/proto/v2"
context "golang.org/x/net/context"
)
@@ -114,7 +114,7 @@ a5d613`, "\n", "", -1))
primaryKeys = map[string][]byte{
primaryAppId: primaryUserKeyRing,
}
- primaryUserProfile = &keyspb.Profile{
+ primaryUserProfile = &v2pb.Profile{
// TODO(cesarghali): fill nonce.
Keys: primaryKeys,
}
@@ -124,7 +124,7 @@ type Env struct {
s *grpc.Server
server *Server
conn *grpc.ClientConn
- Client keyspb.E2EKeyServiceClient
+ Client v2pb.E2EKeyServiceClient
ctx context.Context
}
@@ -143,15 +143,15 @@ func NewEnv(t *testing.T) *Env {
store := storage.CreateMem(context.Background())
b := builder.New(store.NewEntries())
server := New(store, b.GetTree())
- keyspb.RegisterE2EKeyServiceServer(s, server)
+ v2pb.RegisterE2EKeyServiceServer(s, server)
go s.Serve(lis)
cc, err := grpc.Dial(addr, grpc.WithTimeout(time.Millisecond*500))
if err != nil {
t.Fatalf("Dial(%q) = %v", addr, err)
}
- client := keyspb.NewE2EKeyServiceClient(cc)
+ client := v2pb.NewE2EKeyServiceClient(cc)
// TODO: replace with test credentials for an authenticated user.
ctx := context.Background()
@@ -173,14 +173,14 @@ func (env *Env) createPrimaryUser(t *testing.T) {
// Marshaling the update entry.
_, userIndex, _ := env.server.Vuf(primaryUserEmail)
userIndexBytes, _ := hex.DecodeString(userIndex)
- updateEntry := &keyspb.Entry{
+ updateEntry := &v2pb.Entry{
Index: userIndexBytes,
}
eBytes, err := proto.Marshal(updateEntry)
if err != nil {
t.Fatalf("Unexpected entry marshalling error %v.", err)
}
- seu := &keyspb.SignedEntryUpdate{
+ seu := &v2pb.SignedEntryUpdate{
Entry: eBytes,
}
// Marshaling the update entry.
@@ -191,9 +191,9 @@ func (env *Env) createPrimaryUser(t *testing.T) {
// Insert valid user. Calling update if the user does not exist will
// insert the user's profile.
- _, err = env.Client.UpdateUser(env.ctx, &keyspb.UpdateUserRequest{
+ _, err = env.Client.UpdateUser(env.ctx, &v2pb.UpdateUserRequest{
UserId: primaryUserEmail,
- Update: &keyspb.EntryUpdateRequest{
+ Update: &v2pb.EntryUpdateRequest{
SignedUpdate: seuBytes,
Profile: pBytes,
},
@@ -216,7 +216,7 @@ func TestGetNonExistantUser(t *testing.T) {
defer env.Close()
ctx := context.Background() // Unauthenticated request.
- _, err := env.Client.GetUser(ctx, &keyspb.GetUserRequest{UserId: "nobody"})
+ _, err := env.Client.GetUser(ctx, &v2pb.GetUserRequest{UserId: "nobody"})
if got, want := grpc.Code(err), codes.NotFound; got != want {
t.Errorf("Query for nonexistant user = %v, want: %v", got, want)
@@ -230,13 +230,13 @@ func TestGetValidUser(t *testing.T) {
env.createPrimaryUser(t)
ctx := context.Background() // Unauthenticated request.
- res, err := env.Client.GetUser(ctx, &keyspb.GetUserRequest{UserId: primaryUserEmail})
+ res, err := env.Client.GetUser(ctx, &v2pb.GetUserRequest{UserId: primaryUserEmail})
if err != nil {
t.Errorf("GetUser failed: %v", err)
}
// Unmarshaling the resulted profile.
- p := new(keyspb.Profile)
+ p := new(v2pb.Profile)
if err := proto.Unmarshal(res.Profile, p); err != nil {
t.Fatalf("Unexpected profile unmarshalling error %v.", err)
}
@@ -261,10 +261,10 @@ func TestUnimplemented(t *testing.T) {
desc string
err error
}{
- {"ListUserHistory", getErr(env.Client.ListUserHistory(env.ctx, &keyspb.ListUserHistoryRequest{}))},
- {"ListSEH", getErr(env.Client.ListSEH(env.ctx, &keyspb.ListSEHRequest{}))},
- {"ListUpdate", getErr(env.Client.ListUpdate(env.ctx, &keyspb.ListUpdateRequest{}))},
- {"ListSteps", getErr(env.Client.ListSteps(env.ctx, &keyspb.ListStepsRequest{}))},
+ {"ListUserHistory", getErr(env.Client.ListUserHistory(env.ctx, &v2pb.ListUserHistoryRequest{}))},
+ {"ListSEH", getErr(env.Client.ListSEH(env.ctx, &v2pb.ListSEHRequest{}))},
+ {"ListUpdate", getErr(env.Client.ListUpdate(env.ctx, &v2pb.ListUpdateRequest{}))},
+ {"ListSteps", getErr(env.Client.ListSteps(env.ctx, &v2pb.ListStepsRequest{}))},
}
for i, test := range tests {
if got, want := grpc.Code(test.err), codes.Unimplemented; got != want {
@@ -282,7 +282,7 @@ func TestUnauthenticated(t *testing.T) {
desc string
err error
}{
- {"UpdateUser", getErr(env.Client.UpdateUser(env.ctx, &keyspb.UpdateUserRequest{UserId: "someoneelse"}))},
+ {"UpdateUser", getErr(env.Client.UpdateUser(env.ctx, &v2pb.UpdateUserRequest{UserId: "someoneelse"}))},
}
for i, test := range tests {
if got, want := grpc.Code(test.err), codes.PermissionDenied; got != want {
@@ -18,7 +18,7 @@ import (
"testing"
proto "github.com/golang/protobuf/proto"
- keyspb "github.com/google/e2e-key-server/proto/v2"
+ v2pb "github.com/google/e2e-key-server/proto/v2"
)
func TestValidateEmail(t *testing.T) {
@@ -38,7 +38,7 @@ func TestValidateKey(t *testing.T) {
env := NewEnv(t)
defer env.Close()
- key := &keyspb.Key{AppId: primaryAppId, Key: primaryKeys[primaryAppId]}
+ key := &v2pb.Key{AppId: primaryAppId, Key: primaryKeys[primaryAppId]}
if err := env.server.validateKey(primaryUserEmail, key); err != nil {
t.Errorf("validateKey(%v) = %v, wanted nil", &key, err)
}
@@ -52,9 +52,9 @@ func TestValidateUpdateUserRequest(t *testing.T) {
if err != nil {
t.Fatalf("Unexpected profile marshalling error %v.", err)
}
- updateUserRequest := &keyspb.UpdateUserRequest{
+ updateUserRequest := &v2pb.UpdateUserRequest{
UserId: primaryUserEmail,
- Update: &keyspb.EntryUpdateRequest{
+ Update: &v2pb.EntryUpdateRequest{
Profile: p,
},
}
@@ -1,3 +1,17 @@
+// Copyright 2015 Google Inc. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
package merkle
import (
View
@@ -41,8 +41,8 @@ type Server struct {
}
// New creates a new instance of the proxy server.
-func New(svr *keyserver.Server) *Server {
- return &Server{svr}
+func New(srv *keyserver.Server) *Server {
+ return &Server{srv}
}
// GetUser returns a user's profile.
View
@@ -82,8 +82,8 @@ a5d613`, "\n", "", -1))
)
type Env struct {
- v1svr *Server
- v2svr *keyserver.Server
+ v1srv *Server
+ v2srv *keyserver.Server
rpcServer *grpc.Server
cc *grpc.ClientConn
ClientV1 v1pb.E2EKeyProxyClient
@@ -107,10 +107,10 @@ func NewEnv(t *testing.T) *Env {
s := grpc.NewServer()
store := storage.CreateMem(context.Background())
b := builder.New(store.NewEntries())
- v2svr := keyserver.New(store, b.GetTree())
- v1svr := New(v2svr)
- v2pb.RegisterE2EKeyServiceServer(s, v2svr)
- v1pb.RegisterE2EKeyProxyServer(s, v1svr)
+ v2srv := keyserver.New(store, b.GetTree())
+ v1srv := New(v2srv)
+ v2pb.RegisterE2EKeyServiceServer(s, v2srv)
+ v1pb.RegisterE2EKeyProxyServer(s, v1srv)
go s.Serve(lis)
cc, err := grpc.Dial(addr, grpc.WithTimeout(time.Millisecond*500))
@@ -123,7 +123,7 @@ func NewEnv(t *testing.T) *Env {
// TODO: replace with test credentials for an authenticated user.
ctx := context.Background()
- return &Env{v1svr, v2svr, s, cc, clientv1, clientv2, ctx}
+ return &Env{v1srv, v2srv, s, cc, clientv1, clientv2, ctx}
}
// Close releases resources allocated by NewEnv.
@@ -141,7 +141,7 @@ func (env *Env) createPrimaryUser(t *testing.T) {
t.Fatalf("Unexpected profile marshalling error %v.", err)
}
// Marshaling the update entry.
- _, userIndex, _ := env.v2svr.Vuf(primaryUserEmail)
+ _, userIndex, _ := env.v2srv.Vuf(primaryUserEmail)
userIndexBytes, _ := hex.DecodeString(userIndex)
updateEntry := &v2pb.Entry{
Index: userIndexBytes,
@@ -21,7 +21,7 @@ import (
)
const (
- USER_ID_KEYWORD = "user_id"
+ UserIdKeyword = "user_id"
)
// URLParser parses a URL and stores the results in a protobuf structure that
Oops, something went wrong.

0 comments on commit 85519fb

Please sign in to comment.