Skip to content

Commit

Permalink
Add cli e2e tests
Browse files Browse the repository at this point in the history
Add debug print in cmd_membership

Add cli test events

Fix README documentation regarding cli test events
  • Loading branch information
iknite committed Dec 10, 2018
1 parent 2bb5450 commit 9fd0d7e
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 33 deletions.
63 changes: 32 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,47 +61,48 @@ Our work draws strongly from the **Balloon proposals**, with some modifications
- add event

```
go run \
main.go \
--apikey my-key \
client \
--endpoint http://localhost:8080 \
add \
--key 'test event' \
--value 2 \
--log info
go run \
main.go \
--apikey my-key \
client \
--endpoint http://localhost:8080 \
add \
--key 'test event' \
--value 2 \
--log info
```
- membership event
```
go run \
main.go \
--apikey my-key \
client \
--endpoint http://localhost:8080 \
membership \
--hyperDigest 10aa40be23fb739332e2b9c849f2f110b2d209346500c24f70db442022ef38f2 \
--historyDigest 776b33eab8ed829ecffab3d579bf7ccbcc126b94bac1aaca7d5d8b0a2687bdec \
--version 0 \
--key 'test event' \
--log info
go run \
main.go \
--apikey my-key \
client \
--endpoint http://localhost:8080 \
membership \
--hyperDigest 3ec11c37f0a53ff5c4cfc3cf2573c33a9721cd25d8e670a3b2be0fda5724bb5c \
--historyDigest 776b33eab8ed829ecffab3d579bf7ccbcc126b94bac1aaca7d5d8b0a2687bdec \
--version 0 \
--key 'test event' \
--log info
```
- verify event
```
go run \
main.go \
--apikey my-key \
client \
--endpoint http://localhost:8080 \
membership \
--hyperDigest 10aa40be23fb739332e2b9c849f2f110b2d209346500c24f70db442022ef38f2 \
--historyDigest 776b33eab8ed829ecffab3d579bf7ccbcc126b94bac1aaca7d5d8b0a2687bdec \
--version 0 \
--key 'test event' \
--log info
go run \
main.go \
--apikey my-key \
client \
--endpoint http://localhost:8080 \
membership \
--hyperDigest 3ec11c37f0a53ff5c4cfc3cf2573c33a9721cd25d8e670a3b2be0fda5724bb5c \
--historyDigest 776b33eab8ed829ecffab3d579bf7ccbcc126b94bac1aaca7d5d8b0a2687bdec \
--version 0 \
--key 'test event' \
--log info \
--verify
```
## Useful commands
Expand Down
23 changes: 22 additions & 1 deletion cmd/client_membership.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ func newMembershipCommand(ctx *clientContext) *cobra.Command {
Long: `Query for membership of an event to the authenticated data structure.
It also verifies the proofs provided by the server if flag enabled.`,
PreRunE: func(cmd *cobra.Command, args []string) error {
if key == "" && eventDigest == "" {
log.Errorf("Error: trying to get membership without either key or eventDigest")
}
if verify {
if hyperDigest == "" {
log.Errorf("Error: trying to verify proof without hyper digest")
Expand Down Expand Up @@ -68,6 +71,24 @@ func newMembershipCommand(ctx *clientContext) *cobra.Command {
if err != nil {
return err
}
log.Debugf(`MembershipResult:
Exists: %b
Hyper: <TRUNCATED>
History: <TRUNCATED>
CurrentVersion: %d
QueryVersion: %d
ActualVersion: %d
KeyDigest: %x
Key: %s`,
membershipResult.Exists,
// membershipResult.Hyper,
// membershipResult.History,
membershipResult.CurrentVersion,
membershipResult.QueryVersion,
membershipResult.ActualVersion,
membershipResult.KeyDigest,
membershipResult.Key,
)

if verify {
hdBytes, _ := hex.DecodeString(hyperDigest)
Expand All @@ -77,7 +98,7 @@ func newMembershipCommand(ctx *clientContext) *cobra.Command {
log.Infof("Verifying with Snapshot: \n\tEventDigest:%x\n\tHyperDigest: %s\n\tHistoryDigest: %s\n\tVersion: %d\n",
digest, hyperDigest, historyDigest, version)

if ctx.client.Verify(membershipResult, snapshot, hasherF) {
if ctx.client.DigestVerify(membershipResult, snapshot, hasherF) {
log.Info("Verify: OK")
} else {
log.Info("Verify: KO")
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/add_verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
See the License for the specific language governing permissions and
limitations under the License.
*/

package e2e

import (
Expand Down
102 changes: 102 additions & 0 deletions tests/e2e/cli_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
Copyright 2018 Banco Bilbao Vizcaya Argentaria, S.A.
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 e2e

import (
"fmt"
"os/exec"
"strings"
"testing"

"github.com/bbva/qed/testutils/scope"

assert "github.com/stretchr/testify/require"
)

func TestCli(t *testing.T) {
before, after := setup(0, "", t)
scenario, let := scope.Scope(t, before, after)

scenario("Add one event through cli and verify it", func() {

let("Add event", func(t *testing.T) {
cmd := exec.Command("go",
"run",
"./../../main.go",
"--apikey=my-key",
"client",
"--endpoint=http://localhost:8500",
"add",
"--key='test event'",
"--value=2",
"--log=info",
)

_, err := cmd.CombinedOutput()

assert.NoError(t, err, "Subprocess must not exit with status 1")
})

let("verify event with eventDigest", func(t *testing.T) {
cmd := exec.Command("go",
"run",
"./../../main.go",
"--apikey=my-key",
"client",
"--endpoint=http://localhost:8500",
"membership",
"--hyperDigest=81ae2d8f6ecec9c5837d12a09e3b42a1c880b6c77f81ff1f85aef36dac4fdf6a",
"--historyDigest=0f5129eaf5dbfb1405ff072a04d716aaf4e4ba4247a3322c41582e970dbb7b00",
"--version=0",
"--eventDigest=8694718de4363adf07ec3b4aff4c76589f60fe89a7715bee7c8b250e06493922",
"--log=info",
"--verify",
)

stdoutStderr, err := cmd.CombinedOutput()

assert.NoError(t, err, "Subprocess must not exit with status 1")
assert.True(t, strings.Contains(fmt.Sprintf("%s", stdoutStderr), "Verify: OK"), "Must verify with eventDigest")

})

let("verify event with eventDigest", func(t *testing.T) {

cmd := exec.Command("go",
"run",
"./../../main.go",
"--apikey=my-key",
"client",
"--endpoint=http://localhost:8500",
"membership",
"--hyperDigest=81ae2d8f6ecec9c5837d12a09e3b42a1c880b6c77f81ff1f85aef36dac4fdf6a",
"--historyDigest=0f5129eaf5dbfb1405ff072a04d716aaf4e4ba4247a3322c41582e970dbb7b00",
"--version=0",
"--key='test event'",
"--log=info",
"--verify",
)

stdoutStderr, err := cmd.CombinedOutput()

assert.NoError(t, err, "Subprocess must not exit with status 1")
assert.True(t, strings.Contains(fmt.Sprintf("%s", stdoutStderr), "Verify: OK"), "Must verify with eventDigest")

})

})
}
2 changes: 1 addition & 1 deletion tests/e2e/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var apiKey, storageType, listenAddr, keyFile string
var cacheSize uint64

func init() {
apiKey = "my-awesome-api-key"
apiKey = "my-key"
cacheSize = 50000
storageType = "badger"

Expand Down

0 comments on commit 9fd0d7e

Please sign in to comment.