From 3ccede038e98b579cf8ff757351e29cb7106f525 Mon Sep 17 00:00:00 2001 From: grapebaba <281165273@qq.com> Date: Fri, 5 Aug 2016 18:05:07 +0800 Subject: [PATCH] Add rest api bddtests Init rest api bddtests, first cover GetTransactionCert(). Fix Github issue #2363 Change-Id: I55c23eb25d1d6caac06ad6893fd5eef1e35e2d3b Signed-off-by: grapebaba <281165273@qq.com> --- bddtests/docker-compose-rest.yml | 17 +++++++++++ bddtests/peer_rest.feature | 23 ++++++++++++++ bddtests/steps/peer_basic_impl.py | 1 + bddtests/steps/peer_rest_impl.py | 51 +++++++++++++++++++++++++++++++ 4 files changed, 92 insertions(+) create mode 100644 bddtests/docker-compose-rest.yml create mode 100644 bddtests/peer_rest.feature create mode 100644 bddtests/steps/peer_rest_impl.py diff --git a/bddtests/docker-compose-rest.yml b/bddtests/docker-compose-rest.yml new file mode 100644 index 00000000000..c062c7da350 --- /dev/null +++ b/bddtests/docker-compose-rest.yml @@ -0,0 +1,17 @@ +membersrvc0: + extends: + file: compose-defaults.yml + service: membersrvc + +vp0: + extends: + file: compose-defaults.yml + service: vp + environment: + - CORE_PEER_ID=vp0 + - CORE_SECURITY_ENABLED=true + - CORE_PEER_PKI_ECA_PADDR=membersrvc0:7054 + - CORE_PEER_PKI_TCA_PADDR=membersrvc0:7054 + - CORE_PEER_PKI_TLSCA_PADDR=membersrvc0:7054 + links: + - membersrvc0 \ No newline at end of file diff --git a/bddtests/peer_rest.feature b/bddtests/peer_rest.feature new file mode 100644 index 00000000000..78476f26da6 --- /dev/null +++ b/bddtests/peer_rest.feature @@ -0,0 +1,23 @@ +# +# Test REST API Features of Peers +# +# Tags that can be used and will affect test internals: +# @doNotDecompose will NOT decompose the named compose_yaml after scenario ends. Useful for setting up environment and reviewing after scenario. +# @chaincodeImagesUpToDate use this if all scenarios chaincode images are up to date, and do NOT require building. BE SURE!!! + +Feature: Peer REST API + As a Fabric developer + I want to verify REST API behavior + + Scenario: 1 peer and 1 membersrvc, query transaction certs with query parameter count + Given we compose "docker-compose-rest.yml" + And I use the following credentials for querying peers: + | peer | username | secret | + | vp0 | test_user0 | MS9qrN8hFjlE | + And I register with CA supplying username "test_user0" and secret "MS9qrN8hFjlE" on peers: + | vp0 | + + When I request transaction certs with query parameters on "vp0" + | key | value | + | count | 1 | + Then I should get a JSON response with "1" different transaction certs \ No newline at end of file diff --git a/bddtests/steps/peer_basic_impl.py b/bddtests/steps/peer_basic_impl.py index 1aa8951d14d..cb1588ecc7f 100644 --- a/bddtests/steps/peer_basic_impl.py +++ b/bddtests/steps/peer_basic_impl.py @@ -19,6 +19,7 @@ import re import time import copy +from behave import * from datetime import datetime, timedelta import sys, requests, json diff --git a/bddtests/steps/peer_rest_impl.py b/bddtests/steps/peer_rest_impl.py new file mode 100644 index 00000000000..59f25d9bf9c --- /dev/null +++ b/bddtests/steps/peer_rest_impl.py @@ -0,0 +1,51 @@ +# +# Copyright IBM Corp. 2016 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. +# + +import requests +from behave import * +from peer_basic_impl import buildUrl +from peer_basic_impl import getAttributeFromJSON + +import bdd_test_util + + +@when(u'I request transaction certs with query parameters on "{containerName}"') +def step_impl(context, containerName): + assert 'table' in context, "table (of query parameters) not found in context" + assert 'userName' in context, "userName not found in context" + assert 'compose_containers' in context, "compose_containers not found in context" + + ipAddress = bdd_test_util.ipFromContainerNamePart(containerName, context.compose_containers) + request_url = buildUrl(context, ipAddress, "/registrar/{0}/tcert".format(context.userName)) + print("Requesting path = {0}".format(request_url)) + queryParams = {} + for row in context.table.rows: + key, value = row['key'], row['value'] + queryParams[key] = value + + print("Query parameters = {0}".format(queryParams)) + resp = requests.get(request_url, params=queryParams, headers={'Accept': 'application/json'}, verify=False) + + assert resp.status_code == 200, "Failed to GET to %s: %s" % (request_url, resp.text) + context.response = resp + print("") + +@then(u'I should get a JSON response with "{expectedValue}" different transaction certs') +def step_impl(context, expectedValue): + print(context.response.json()) + foundValue = getAttributeFromJSON("OK", context.response.json(), "Attribute not found in response (OK)") + print(len(set(foundValue))) + assert (len(set(foundValue)) == int(expectedValue)), "For attribute OK, expected different transaction cert of size (%s), instead found (%s)" % (expectedValue, len(set(foundValue))) \ No newline at end of file