Skip to content

Commit dfeef95

Browse files
Lagovasvixentael
authored andcommitted
test examples (#92)
Update circle.yml and tests
1 parent 0bb8c42 commit dfeef95

File tree

8 files changed

+107
-58
lines changed

8 files changed

+107
-58
lines changed

circle.yml

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,9 @@
1-
#
2-
# Copyright (c) 2017 Cossack Labs Limited
3-
#
4-
# This file is a part of Hermes-core.
5-
#
6-
# Hermes-core is free software: you can redistribute it and/or modify
7-
# it under the terms of the GNU Affero General Public License as published by
8-
# the Free Software Foundation, either version 3 of the License, or
9-
# (at your option) any later version.
10-
#
11-
# Hermes-core is distributed in the hope that it will be useful,
12-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14-
# GNU Affero General Public License for more details.
15-
#
16-
# You should have received a copy of the GNU Affero General Public License
17-
# along with Hermes-core. If not, see <http://www.gnu.org/licenses/>.
18-
#
19-
#
1+
machine:
2+
environment:
3+
# circleci has several folders in gopath so place our gopath first in gopath list to simplify copying code into
4+
# gopath directories below
5+
TEMP_GOPATH: ${HOME}/temp_gopath
6+
GOPATH: $TEMP_GOPATH:$GOPATH
207

218
dependencies:
229
pre:
@@ -26,11 +13,33 @@ dependencies:
2613
override:
2714
- make
2815
- sudo make install
16+
- make examples
2917
- sudo pip install tox
3018
- pyenv global 2.7.12 3.3.6 3.4.4 3.5.3 3.6.2
19+
- mkdir -p db/credential_store db/key_store db/data_store
20+
- cp ./docs/examples/c/service_keys/* db/credential_store/
21+
- cp ./docs/examples/test_keys/* db/credential_store/
22+
# copy current code from commit to our gopath
23+
- mkdir -p $TEMP_GOPATH/src/github.com/cossacklabs
24+
# link current code to gopath to avoid fetching via go get
25+
- ln -s ${HOME}/${CIRCLE_PROJECT_REPONAME} $TEMP_GOPATH/src/github.com/cossacklabs/${CIRCLE_PROJECT_REPONAME}
26+
# fetch go example's dependencies
27+
- go get -t -d ./docs/examples/go/...
28+
- go build docs/examples/go/hermes_client.go
29+
- cd pyhermes && python setup.py install
30+
3131

3232
test:
3333
override:
3434
- make test
35-
# run only TestHermesTransport until add support of running stores
36-
- cd pyhermes && tox -e py33,py34,py35,py36,py27 -- python -m unittest test.TestHermesTransport
35+
# test pyhermes
36+
- ./tests/scripts/test_services.sh "cd pyhermes && tox -e py33,py34,py35,py36,py27 -- python -m unittest test.TestHermesTransport test.TestHermes.test_secure_midhermes";
37+
38+
# test golang tutorial
39+
- ./tests/scripts/test_services.sh docs/examples/go/tests/go_test.sh;
40+
41+
# test python tutorial
42+
- ./tests/scripts/test_services.sh docs/examples/python/tests/test.sh;
43+
44+
# test c tutorial
45+
- ./tests/scripts/test_services.sh docs/examples/c/tests/test.sh;

docs/examples/c/mid_hermes/client/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ all:
44
../common/transport.c \
55
../../utils/utils.c \
66
../../utils/base64.c \
7+
-std=c99 \
78
-lhermes_mid_hermes \
89
-lhermes_mid_hermes_ll \
910
-lhermes_credential_store \
@@ -18,4 +19,4 @@ all:
1819
-o client
1920

2021
clean:
21-
@rm ./client
22+
@rm ./client

docs/examples/c/tests/test.sh

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ PRIVATE_KEY2=UkVDMgAAAC00lzw7ABmvKHvjOqWW8i+dxwHTU8RzuaATkZNBcLmCm8TBxRn2
3535
PUBLIC_KEY2=VUVDMgAAAC0lAFeZAqw+nKzco1l2qtXELqVr7fmpsMf4hSrOa/TkAu5OQ6Cy
3636

3737
# path to dir where are compiled client binary
38-
BIN=cmake-build-debug
38+
BIN=./docs/examples/c/mid_hermes/client
3939
SUCCESS=0
4040
FAIL=1
4141
DB_DIR=db/credential_store
@@ -50,22 +50,22 @@ echo -n $DATASTORE_PUBLIC | base64 --decode > $DB_DIR/`echo -n "data_store_serve
5050
# add block
5151
echo "add block"
5252
$BIN/client add_block $USER_ID $PRIVATE_KEY $TEST_FILE "metadata" 1>/dev/null
53-
if [ $? -eq $FAIL ]; then
53+
if [ ! $? -eq $SUCCESS ]; then
5454
exit 1
5555
fi
5656

5757
# read block
5858
echo "read block"
5959
$BIN/client read_block $USER_ID $PRIVATE_KEY $TEST_FILE 1>/dev/null
60-
if [ $? -eq $FAIL ]; then
60+
if [ ! $? -eq $SUCCESS ]; then
6161
exit 1
6262
fi
6363

6464
# update block
6565
echo "update block"
6666
echo "some new content" > $TEST_FILE
6767
$BIN/client update_block $USER_ID $PRIVATE_KEY $TEST_FILE "new metadata" 1>/dev/null
68-
if [ $? -eq $FAIL ]; then
68+
if [ ! $? -eq $SUCCESS ]; then
6969
exit 1
7070
fi
7171

@@ -80,14 +80,14 @@ fi
8080
# grant access
8181
echo "grant read access"
8282
$BIN/client grant_read $USER_ID $PRIVATE_KEY $TEST_FILE $USER_ID2 1>/dev/null
83-
if [ $? -eq $FAIL ]; then
83+
if [ ! $? -eq $SUCCESS ]; then
8484
exit 1
8585
fi
8686

8787
# read by user 2
8888
echo "read by user 2"
8989
$BIN/client read_block $USER_ID2 $PRIVATE_KEY2 $TEST_FILE 1>/dev/null
90-
if [ $? -eq $FAIL ]; then
90+
if [ ! $? -eq $SUCCESS ]; then
9191
exit 1
9292
fi
9393

@@ -103,23 +103,23 @@ fi
103103
echo "grant update"
104104
# grant update to user 2
105105
$BIN/client grant_update $USER_ID $PRIVATE_KEY $TEST_FILE $USER_ID2 1>/dev/null
106-
if [ $? -eq $FAIL ]; then
106+
if [ ! $? -eq $SUCCESS ]; then
107107
exit 1
108108
fi
109109

110110
# update block
111111
echo "update block by user 2"
112112
echo "some new content by user2" > $TEST_FILE
113113
$BIN/client update_block $USER_ID2 $PRIVATE_KEY2 $TEST_FILE "new metadata" 1>/dev/null
114-
if [ $? -eq $FAIL ]; then
114+
if [ ! $? -eq $SUCCESS ]; then
115115
exit 1
116116
fi
117117

118118

119119
# revoke update from user 2
120120
echo "revoke update"
121121
$BIN/client revoke_update $USER_ID $PRIVATE_KEY $TEST_FILE $USER_ID2 1>/dev/null
122-
if [ $? -eq $FAIL ]; then
122+
if [ ! $? -eq $SUCCESS ]; then
123123
exit 1
124124
fi
125125

@@ -134,7 +134,7 @@ fi
134134
# revoke read from user 2
135135
echo "revoke read"
136136
$BIN/client revoke_read $USER_ID $PRIVATE_KEY $TEST_FILE $USER_ID2 1>/dev/null
137-
if [ $? -eq $FAIL ]; then
137+
if [ ! $? -eq $SUCCESS ]; then
138138
exit 1
139139
fi
140140

@@ -148,6 +148,6 @@ fi
148148
# delete block
149149
echo "delete block"
150150
$BIN/client delete_block $USER_ID $PRIVATE_KEY $TEST_FILE 1>/dev/null
151-
if [ $? -eq $FAIL ]; then
151+
if [ ! $? -eq $SUCCESS ]; then
152152
exit 1
153-
fi
153+
fi

docs/examples/go/tests/go_test.sh

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,22 @@ echo -n $DATASTORE_PUBLIC | base64 --decode > $DB_DIR/`echo -n "data_store_serve
5151
# add block
5252
echo "add block"
5353
$BIN/hermes_client -command=add_block -id=$USER_ID -private_key=$PRIVATE_KEY -config=$CONFIG_PATH -doc $TEST_FILE -meta="some meta data" 1>/dev/null
54-
if [ $? -eq $FAIL ]; then
54+
if [ ! $? -eq $SUCCESS ]; then
5555
exit 1
5656
fi
5757

5858
# read block
5959
echo "read block"
6060
$BIN/hermes_client -command=read_block -id=$USER_ID -private_key=$PRIVATE_KEY -config=$CONFIG_PATH -doc $TEST_FILE 1>/dev/null
61-
if [ $? -eq $FAIL ]; then
61+
if [ ! $? -eq $SUCCESS ]; then
6262
exit 1
6363
fi
6464

6565
# update block
6666
echo "update block"
6767
echo "some new content" > $TEST_FILE
6868
$BIN/hermes_client -command=update_block -id=$USER_ID -private_key=$PRIVATE_KEY -config=$CONFIG_PATH -doc $TEST_FILE -meta="new metadata" 1>/dev/null
69-
if [ $? -eq $FAIL ]; then
69+
if [ ! $? -eq $SUCCESS ]; then
7070
exit 1
7171
fi
7272

@@ -81,14 +81,14 @@ fi
8181
# grant access
8282
echo "grant read access"
8383
$BIN/hermes_client -command=grant_read_access -id=$USER_ID -private_key=$PRIVATE_KEY -config=$CONFIG_PATH -doc $TEST_FILE -for_user=$USER_ID2 1>/dev/null
84-
if [ $? -eq $FAIL ]; then
84+
if [ ! $? -eq $SUCCESS ]; then
8585
exit 1
8686
fi
8787

8888
# read by user 2
8989
echo "read by user 2"
9090
$BIN/hermes_client -command=read_block -id=$USER_ID2 -private_key=$PRIVATE_KEY2 -config=$CONFIG_PATH -doc $TEST_FILE 1>/dev/null
91-
if [ $? -eq $FAIL ]; then
91+
if [ ! $? -eq $SUCCESS ]; then
9292
exit 1
9393
fi
9494

@@ -104,23 +104,23 @@ fi
104104
echo "grant update"
105105
# grant update to user 2
106106
$BIN/hermes_client -command=grant_update_access -id=$USER_ID -private_key=$PRIVATE_KEY -config=$CONFIG_PATH -doc $TEST_FILE -for_user=$USER_ID2 1>/dev/null
107-
if [ $? -eq $FAIL ]; then
107+
if [ ! $? -eq $SUCCESS ]; then
108108
exit 1
109109
fi
110110

111111
# update block
112112
echo "update block by user 2"
113113
echo "some new content by user2" > $TEST_FILE
114114
$BIN/hermes_client -command=update_block -id=$USER_ID2 -private_key=$PRIVATE_KEY2 -config=$CONFIG_PATH -doc $TEST_FILE -meta="new metadata" 1>/dev/null
115-
if [ $? -eq $FAIL ]; then
115+
if [ ! $? -eq $SUCCESS ]; then
116116
exit 1
117117
fi
118118

119119

120120
# revoke update from user 2
121121
echo "revoke update"
122122
$BIN/hermes_client -command=revoke_update_access -id=$USER_ID -private_key=$PRIVATE_KEY -config=$CONFIG_PATH -doc $TEST_FILE -for_user=$USER_ID2 1>/dev/null
123-
if [ $? -eq $FAIL ]; then
123+
if [ ! $? -eq $SUCCESS ]; then
124124
exit 1
125125
fi
126126

@@ -135,7 +135,7 @@ fi
135135
# revoke read from user 2
136136
echo "revoke read"
137137
$BIN/hermes_client -command=revoke_read_access -id=$USER_ID -private_key=$PRIVATE_KEY -config=$CONFIG_PATH -doc $TEST_FILE -for_user=$USER_ID2 1>/dev/null
138-
if [ $? -eq $FAIL ]; then
138+
if [ ! $? -eq $SUCCESS ]; then
139139
exit 1
140140
fi
141141

@@ -149,6 +149,6 @@ fi
149149
# delete block
150150
echo "delete block"
151151
$BIN/hermes_client -command=delete_block -id=$USER_ID -private_key=$PRIVATE_KEY -config=$CONFIG_PATH -doc $TEST_FILE 1>/dev/null
152-
if [ $? -eq $FAIL ]; then
152+
if [ ! $? -eq $SUCCESS ]; then
153153
exit 1
154-
fi
154+
fi

docs/examples/python/tests/test.sh

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,14 @@
2222
TEST_FILE=/tmp/testfile
2323
echo "some content" > $TEST_FILE
2424
USER_ID=user1
25-
PRIVATE_KEY1=/path/to/private/key1
25+
PRIVATE_KEY1=/tmp/user1.priv
26+
PRIVATE_KEY_BASE64=UkVDMgAAAC0Tj5tGAPfpgfYMBACxX6onvlWvcc2Gb9ZylBlJdjebTpV3OCIx
27+
echo -n $PRIVATE_KEY_BASE64 | base64 -d > $PRIVATE_KEY1
2628

2729
USER_ID2=user2
28-
PRIVATE_KEY2=/path/to/private/key2
30+
PRIVATE_KEY2=/tmp/user2.priv
31+
PRIVATE_KEY2_BASE64=UkVDMgAAAC00lzw7ABmvKHvjOqWW8i+dxwHTU8RzuaATkZNBcLmCm8TBxRn2
32+
echo -n $PRIVATE_KEY2_BASE64 | base64 -d > $PRIVATE_KEY2
2933
CONFIG=docs/examples/python/config.json
3034
BIN=docs/examples/python/hermes_client.py
3135

@@ -35,22 +39,22 @@ FAIL=1
3539
# add block
3640
echo "add block"
3741
python $BIN --id $USER_ID --private_key $PRIVATE_KEY1 --doc $TEST_FILE --meta "metadata" --config=$CONFIG --add
38-
if [ $? -eq $FAIL ]; then
42+
if [ ! $? -eq $SUCCESS ]; then
3943
exit 1
4044
fi
4145

4246
# read block
4347
echo "read block"
4448
python $BIN --id $USER_ID --private_key $PRIVATE_KEY1 --doc $TEST_FILE --config=$CONFIG --read
45-
if [ $? -eq $FAIL ]; then
49+
if [ ! $? -eq $SUCCESS ]; then
4650
exit 1
4751
fi
4852

4953
# update block
5054
echo "update block"
5155
echo "some new content" > $TEST_FILE
5256
python $BIN --id $USER_ID --private_key $PRIVATE_KEY1 --doc $TEST_FILE --meta "new metadata" --config=$CONFIG --update
53-
if [ $? -eq $FAIL ]; then
57+
if [ ! $? -eq $SUCCESS ]; then
5458
exit 1
5559
fi
5660

@@ -65,14 +69,14 @@ fi
6569
# grant access
6670
echo "grant read access"
6771
python $BIN --id $USER_ID --private_key $PRIVATE_KEY1 --doc $TEST_FILE --config=$CONFIG --grant_read --for_user=$USER_ID2
68-
if [ $? -eq $FAIL ]; then
72+
if [ ! $? -eq $SUCCESS ]; then
6973
exit 1
7074
fi
7175

7276
# read by user 2
7377
echo "read by user 2"
7478
python $BIN --id $USER_ID2 --private_key $PRIVATE_KEY2 --doc $TEST_FILE --config=$CONFIG --read
75-
if [ $? -eq $FAIL ]; then
79+
if [ ! $? -eq $SUCCESS ]; then
7680
exit 1
7781
fi
7882

@@ -88,23 +92,23 @@ fi
8892
echo "grant update"
8993
# grant update to user 2
9094
python $BIN --id $USER_ID --private_key $PRIVATE_KEY1 --doc $TEST_FILE --config=$CONFIG --grant_update --for_user=$USER_ID2
91-
if [ $? -eq $FAIL ]; then
95+
if [ ! $? -eq $SUCCESS ]; then
9296
exit 1
9397
fi
9498

9599
# update block
96100
echo "update block by user 2"
97101
echo "some new content by user2" > $TEST_FILE
98102
python $BIN --id $USER_ID2 --private_key $PRIVATE_KEY2 --doc $TEST_FILE --meta "new metadata 2" --config=$CONFIG --update
99-
if [ $? -eq $FAIL ]; then
103+
if [ ! $? -eq $SUCCESS ]; then
100104
exit 1
101105
fi
102106

103107

104108
# revoke update from user 2
105109
echo "revoke update"
106110
python $BIN --id $USER_ID --private_key $PRIVATE_KEY1 --doc $TEST_FILE --config=$CONFIG --revoke_update --for_user=$USER_ID2
107-
if [ $? -eq $FAIL ]; then
111+
if [ ! $? -eq $SUCCESS ]; then
108112
exit 1
109113
fi
110114

@@ -119,7 +123,7 @@ fi
119123
# revoke read from user 2
120124
echo "revoke read"
121125
python $BIN --id $USER_ID --private_key $PRIVATE_KEY1 --doc $TEST_FILE --config=$CONFIG --revoke_read --for_user=$USER_ID2
122-
if [ $? -eq $FAIL ]; then
126+
if [ ! $? -eq $SUCCESS ]; then
123127
exit 1
124128
fi
125129

@@ -133,6 +137,6 @@ fi
133137
# delete block
134138
echo "delete block"
135139
python $BIN --id $USER_ID --private_key $PRIVATE_KEY1 --doc $TEST_FILE --config=$CONFIG --delete
136-
if [ $? -eq $FAIL ]; then
140+
if [ ! $? -eq $SUCCESS ]; then
137141
exit 1
138-
fi
142+
fi

docs/examples/test_keys/dXNlcjE=

45 Bytes
Binary file not shown.

docs/examples/test_keys/dXNlcjI=

45 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)