diff --git a/.circleci/config.yml b/.circleci/config.yml index e5bc346..75c5fc6 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,45 +3,26 @@ jobs: build: docker: # CircleCI Go images available at: https://hub.docker.com/r/circleci/golang/ - - image: circleci/golang:1.10.1 - working_directory: ~/ndid/test + - image: ndidplatform/base-test + working_directory: /ndid/test steps: - checkout - - run: - name: Install Node.js - command: curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash - && sudo apt-get install -y nodejs - - run: - name: Install Tendermint ABCI - command: go get github.com/tendermint/abci/cmd/abci-cli - - run: - name: Install Tendermint - command: | - wget https://github.com/tendermint/tendermint/releases/download/v0.16.0/tendermint_0.16.0_linux_amd64.zip - unzip tendermint_0.16.0_linux_amd64.zip - sudo install tendermint /usr/local/bin - - run: - name: Install Yarn - command: | - curl -o- -L https://yarnpkg.com/install.sh | bash - run: name: Install test dependencies command: | - ~/.yarn/bin/yarn --frozen-lockfile - - run: - name: Create logs directory - command: | - mkdir -p ~/logs - + ~/.yarn/bin/yarn - run: git clone https://github.com/ndidplatform/smart-contract.git /go/src/github.com/ndidplatform/smart-contract - run: name: 'Install smart-contract dependencies (todo: use a dep management solution?)' command: | - go get github.com/fatih/color - - run: git clone https://github.com/ndidplatform/api.git ~/ndid/api + cd /go/src/github.com/ndidplatform/smart-contract/abci + dep ensure + go install + - run: git clone https://github.com/ndidplatform/api.git /ndid/api - run: name: 'Install api dependencies' command: | - cd ~/ndid/api + cd /ndid/api npm install #region Start IDP node @@ -51,7 +32,7 @@ jobs: ( cd /go/src/github.com/ndidplatform/smart-contract CALLBACK_URI=http://localhost:3000/callback go run abci/server.go tcp://127.0.0.1:46000 - ) 2>&1 | tee -a ~/logs/idp-abci.log + ) 2>&1 | tee -a /ndid/logs/idp-abci.log background: true - run: name: idp-tendermint @@ -60,7 +41,7 @@ jobs: cd /go/src/github.com/ndidplatform/smart-contract tendermint --home ./config/tendermint/IdP unsafe_reset_all tendermint --home ./config/tendermint/IdP node --consensus.create_empty_blocks=false - ) 2>&1 | tee -a ~/logs/idp-tendermint.log + ) 2>&1 | tee -a /ndid/logs/idp-tendermint.log background: true #endregion #region Start RP node @@ -70,7 +51,7 @@ jobs: ( cd /go/src/github.com/ndidplatform/smart-contract CALLBACK_URI=http://localhost:3001/callback go run abci/server.go tcp://127.0.0.1:46001 - ) 2>&1 | tee -a ~/logs/rp-abci.log + ) 2>&1 | tee -a /ndid/logs/rp-abci.log background: true - run: name: rp-tendermint @@ -79,41 +60,62 @@ jobs: cd /go/src/github.com/ndidplatform/smart-contract tendermint --home ./config/tendermint/RP unsafe_reset_all tendermint --home ./config/tendermint/RP node --consensus.create_empty_blocks=false - ) 2>&1 | tee -a ~/logs/rp-tendermint.log + ) 2>&1 | tee -a /ndid/logs/rp-tendermint.log background: true #endregion - - run: node waitForLog --file=$HOME/logs/idp-abci.log --text=Commit --count=2 - - run: node waitForLog --file=$HOME/logs/rp-abci.log --text=Commit --count=2 + - run: node waitForLog --file=/ndid/logs/idp-abci.log --text=Commit --count=2 + - run: node waitForLog --file=/ndid/logs/rp-abci.log --text=Commit --count=2 #region Start IDP API + - run: + name: Initialize Dev Key + command: | + cd /ndid/api + npm run initDevKey - run: name: idp-api command: | - cd ~/ndid/api - ROLE=idp \ - MQ_CONTACT_IP=127.0.0.1 \ - MQ_BINDING_PORT=5555 \ - ABCI_APP_CALLBACK_PORT=3000 \ - SERVER_PORT=8080 \ - npm start + ( + cd /ndid/api + ROLE=idp \ + MQ_CONTACT_IP=127.0.0.1 \ + MQ_BINDING_PORT=5555 \ + ABCI_APP_CALLBACK_PORT=3000 \ + SERVER_PORT=8080 \ + npm start + ) 2>&1 | tee -a /ndid/logs/idp-api.log background: true - run: name: rp-api command: | - cd ~/ndid/api - ROLE=rp \ - ABCI_APP_CALLBACK_PORT=3001 \ - MQ_CONTACT_IP=127.0.0.1 \ - MQ_BINDING_PORT=5556 \ - SERVER_PORT=8081 \ - npm start + ( + cd /ndid/api + ROLE=rp \ + ABCI_APP_CALLBACK_PORT=3001 \ + MQ_CONTACT_IP=127.0.0.1 \ + MQ_BINDING_PORT=5556 \ + SERVER_PORT=8081 \ + npm start + ) 2>&1 | tee -a /ndid/logs/rp-api.log background: true - - run: node waitForLog --file=$HOME/logs/idp-abci.log --text=Commit --count=3 - - run: node waitForLog --file=$HOME/logs/rp-abci.log --text=Commit --count=3 + - run: node waitForLog --file=/ndid/logs/idp-abci.log --text=Commit --count=3 + - run: node waitForLog --file=/ndid/logs/rp-abci.log --text=Commit --count=3 #endregion + - run: + name: Run Newman + command: | + sleep 3 + curl --header 'Content-Type: Application/json' -X POST --data " {\"namespace\": \"uuidTest1\", \"identifier\" : \"12345\", \"secret\":\"MAGIC\", \"accessor_type\":\"awesome-type\", \"accessor_key\":\"awesome-key\",\"accessor_id\":\"some-awesome-accessor\"}" http://localhost:8080/identity + sleep 1 + newman run postman/relying_party.postman_collection.json -e postman/env1.postman_environment.json --reporters junit,cli #region Post-test + - store_test_results: + path: /ndid/test/newman - store_artifacts: - path: ~/logs + path: /ndid/logs destination: logs + - store_artifacts: + path: /ndid/test/newman + destination: tests #endregion diff --git a/postman/env1.postman_environment.json b/postman/env1.postman_environment.json new file mode 100644 index 0000000..499f3dc --- /dev/null +++ b/postman/env1.postman_environment.json @@ -0,0 +1,39 @@ +{ + "id": "c0caabb4-fcb0-47c4-9641-90974cd2324d", + "name": "env1", + "values": [ + { + "key": "url_idp", + "value": "127.0.0.1:8080", + "enabled": true, + "type": "text" + }, + { + "key": "url_rp", + "value": "127.0.0.1:8081", + "enabled": true, + "type": "text" + }, + { + "key": "url_as", + "value": "127.0.0.1:8082", + "enabled": true, + "type": "text" + }, + { + "key": "namespace", + "value": "uuidTest1", + "enabled": true, + "type": "text" + }, + { + "key": "identifier", + "value": "12345", + "enabled": true, + "type": "text" + } + ], + "_postman_variable_scope": "environment", + "_postman_exported_at": "2018-05-21T10:51:53.502Z", + "_postman_exported_using": "Postman/6.0.10" +} diff --git a/postman/relying_party.postman_collection.json b/postman/relying_party.postman_collection.json new file mode 100644 index 0000000..a526be3 --- /dev/null +++ b/postman/relying_party.postman_collection.json @@ -0,0 +1,375 @@ +{ + "info": { + "_postman_id": "9f50b7c6-eaaa-41bf-8de7-963428b386f5", + "name": "Relying_party", + "description": "API for RP specific functions and roles", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" + }, + "item": [ + { + "name": "POST /rp/requests/{namespace}/{identifier}", + "description": "/rp/requests/{namespace}/{identifier}\n", + "item": [ + { + "name": "reference_id", + "description": "", + "item": [ + { + "name": "Case: Input reference id with empty", + "event": [ + { + "listen": "test", + "script": { + "id": "adb45711-3b6d-42d5-bc25-da78cc2e3553", + "type": "text/javascript", + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.response.to.have.status(400);", + "});", + "", + "", + "", + "pm.test('Should shows error \"should not be shorter than 1 characters\"' , function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.errors[0].message).to.eql(\"should NOT be shorter than 1 characters\");", + "});" + ] + } + }, + { + "listen": "prerequest", + "script": { + "id": "f28ea516-45c4-44b7-8d6f-b0660216135c", + "type": "text/javascript", + "exec": [ + "" + ] + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"reference_id\": \"\",\n \"idp_list\": [\n \"idp1\"\n ],\n \"callback_url\": \"string\",\n \"as_service_list\": [\n {\n \"service_id\": \"string\",\n \"as_id\": [\n \"string\"\n ],\n \"count\": 0,\n \"request_params\": {\"key\":\"value\"}\n }\n ],\n \"request_message\": \"string\",\n \"min_ial\": 1.1,\n \"min_aal\": 1,\n \"min_idp\": 1,\n \"request_timeout\": 0\n}" + }, + "url": { + "raw": "{{url_rp}}/rp/requests/{{namespace}}/{{identifier}}", + "host": [ + "{{url_rp}}" + ], + "path": [ + "rp", + "requests", + "{{namespace}}", + "{{identifier}}" + ] + } + }, + "response": [] + }, + { + "name": "Case: Input reference id with space", + "event": [ + { + "listen": "test", + "script": { + "id": "43101a2e-7557-4ab8-953c-2b6b6405aac8", + "type": "text/javascript", + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.response.to.have.status(400);", + "});", + "", + "" + ] + } + }, + { + "listen": "prerequest", + "script": { + "id": "0fbc562e-1dc7-416c-ba3f-425201e5d6b0", + "type": "text/javascript", + "exec": [ + "" + ] + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"reference_id\": \" \",\n \"idp_list\": [\n \"idp1\"\n ],\n \"callback_url\": \"http://localhost\",\n \"as_service_list\": [\n {\n \"service_id\": \"string\",\n \"as_id\": [\n \"string\"\n ],\n \"count\": 1,\n \"request_params\": {\"id\":\"1234\"}\n }\n ],\n \"request_message\": \"OK\",\n \"min_ial\": 1.1,\n \"min_aal\": 1,\n \"min_idp\": 1,\n \"request_timeout\": 0\n}" + }, + "url": { + "raw": "{{url_rp}}/rp/requests/{{namespace}}/{{identifier}}", + "host": [ + "{{url_rp}}" + ], + "path": [ + "rp", + "requests", + "{{namespace}}", + "{{identifier}}" + ] + } + }, + "response": [] + }, + { + "name": "Case: Input reference id with special characters", + "event": [ + { + "listen": "test", + "script": { + "id": "31dad7ae-8ab3-4564-b055-7a15d6f8f3a6", + "type": "text/javascript", + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.response.to.have.status(400);", + "});", + "", + "", + "", + "" + ] + } + }, + { + "listen": "prerequest", + "script": { + "id": "59cdad85-5e7c-45f1-afb8-6cd0c305e22c", + "type": "text/javascript", + "exec": [ + "" + ] + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"reference_id\": \"AaB@#$%^<>\",\n \"idp_list\": [\n \"idp1\"\n ],\n \"callback_url\": \"http://localhost\",\n \"as_service_list\": [\n {\n \"service_id\": \"string\",\n \"as_id\": [\n \"string\"\n ],\n \"count\": 1,\n \"request_params\": {\"id\":\"1234\"}\n }\n ],\n \"request_message\": \"OK\",\n \"min_ial\": 1.1,\n \"min_aal\": 1,\n \"min_idp\": 1,\n \"request_timeout\": 0\n}" + }, + "url": { + "raw": "{{url_rp}}/rp/requests/{{namespace}}/{{identifier}}", + "host": [ + "{{url_rp}}" + ], + "path": [ + "rp", + "requests", + "{{namespace}}", + "{{identifier}}" + ] + } + }, + "response": [] + }, + { + "name": "Case: Input reference id without string", + "event": [ + { + "listen": "test", + "script": { + "id": "c278b8b7-8069-4f8e-b86e-7e49c8cab551", + "type": "text/javascript", + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.response.to.have.status(400);", + "});", + "", + "", + "" + ] + } + }, + { + "listen": "prerequest", + "script": { + "id": "ccd21406-60f3-4ec9-a869-2cf948abf122", + "type": "text/javascript", + "exec": [ + "" + ] + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"reference_id\": 12234,\n \"idp_list\": [\n \t\"idp1\",\"ab12\",\"QEsafd\"\n ],\n \"callback_url\": \"http://localhost\",\n \"as_service_list\": [\n {\n \"service_id\": \"string\",\n \"as_id\": [\n \"string\"\n ],\n \"count\": 1,\n \"request_params\": {\"id\":\"1234\"}\n }\n ],\n \"request_message\": \"OK\",\n \"min_ial\": 1.1,\n \"min_aal\": 1,\n \"min_idp\": 1,\n \"request_timeout\": 0\n}" + }, + "url": { + "raw": "{{url_rp}}/rp/requests/{{namespace}}/{{identifier}}", + "host": [ + "{{url_rp}}" + ], + "path": [ + "rp", + "requests", + "{{namespace}}", + "{{identifier}}" + ] + } + }, + "response": [] + }, + { + "name": "Case: Send request to namespace and identity success", + "event": [ + { + "listen": "test", + "script": { + "id": "a2f0ffba-ffe2-473a-8cc4-1124f47bf94a", + "type": "text/javascript", + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.have.status(200);", + "});" + ] + } + }, + { + "listen": "prerequest", + "script": { + "id": "38243afb-9cb8-444f-8795-e4dfe11a404f", + "type": "text/javascript", + "exec": [ + "" + ] + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"reference_id\": \"ABCDEzxc\",\n \"idp_list\": [\n \"idp1\"\n ],\n \"callback_url\": \"http://localhost\",\n \"as_service_list\": [\n {\n \"service_id\": \"string\",\n \"as_id\": [\n \"string\"\n ],\n \"count\": 1,\n \"request_params\": {\"id\":\"1234\"}\n }\n ],\n \"request_message\": \"OK\",\n \"min_ial\": 1.1,\n \"min_aal\": 1,\n \"min_idp\": 1,\n \"request_timeout\": 0\n}\n" + }, + "url": { + "raw": "{{url_rp}}/rp/requests/{{namespace}}/{{identifier}}", + "host": [ + "{{url_rp}}" + ], + "path": [ + "rp", + "requests", + "{{namespace}}", + "{{identifier}}" + ] + } + }, + "response": [] + } + ], + "_postman_isSubFolder": true + } + ], + "event": [ + { + "listen": "prerequest", + "script": { + "id": "82ddee3f-d81e-4fed-89c0-657074673e3f", + "type": "text/javascript", + "exec": [ + "setTimeout(function () {},1000);", + "var url_idp = pm.variables.get(\"url_idp\");", + "", + "const createIdentity = {", + " url: url_idp +\"/identity\",", + " method: 'POST',", + " header: \"Content-Type:application/json\",", + " body:{", + " mode: 'raw',", + " raw: JSON.stringify({", + " \"namespace\": \"uuid889\",", + " \"identifier\": \"12345\",", + " \"secret\": \"abc\",", + " \"accessor_type\": \"a\",", + " \"accessor_key\": \"ab\",", + " \"accessor_id\": \"cc\"", + " })", + " }", + "};", + "", + "pm.sendRequest(createIdentity, function (err, response) {", + " if (err) {", + " console.log(err);", + " } else {", + " pm.environment.set(\"namespace\", \"uuid889\");", + " pm.environment.set(\"identifier\", \"12345\");", + " }", + "});" + ] + } + }, + { + "listen": "test", + "script": { + "id": "ec1d75b0-c05c-4144-b9d5-e6e6f9171b31", + "type": "text/javascript", + "exec": [ + "" + ] + } + } + ] + } + ], + "event": [ + { + "listen": "prerequest", + "script": { + "id": "043b2dd6-510f-4a05-a591-9afbb5a6cf7d", + "type": "text/javascript", + "exec": [ + "" + ] + } + }, + { + "listen": "test", + "script": { + "id": "f03a263b-d9d7-4307-909c-1c39545da545", + "type": "text/javascript", + "exec": [ + "" + ] + } + } + ] +} \ No newline at end of file diff --git a/waitForLog.js b/waitForLog.js index 83d25e2..62f84ed 100644 --- a/waitForLog.js +++ b/waitForLog.js @@ -15,15 +15,22 @@ function main () { check() } +function exitWhenTimeOff() { + console.log("Exit because it is too long") + process.exit(1) +} + function check () { const data = fs.readFileSync(args.file, 'utf8') const found = data.split(text).length - 1 console.log('Found', found, 'match(es).') if (found >= count) { console.log('Done!') + process.exit(0) } else { setTimeout(check, 1000) } } +setTimeout(exitWhenTimeOff, 60000) main()