blob: 0c194c10ed5a28aef54e0b6a3fe06b33ba7aacf5 [file] [log] [blame]
DR695Hccff30b2017-02-17 18:44:24 -05001*** Settings ***
Brian Freeman19a4d2d2018-11-30 13:03:52 -05002Documentation The main interface for interacting with Message router. It handles low level stuff like managing the http request library and message router required fields
3Library RequestsClientCert
Brian Freemaned66ff92019-05-02 15:30:02 -05004Library RequestsLibrary
Brian Freeman19a4d2d2018-11-30 13:03:52 -05005Library UUID
Brian Freemaned66ff92019-05-02 15:30:02 -05006Library DateTime
7Library Process
8Library JSONUtils
DR695Hccff30b2017-02-17 18:44:24 -05009
10Resource global_properties.robot
Brian Freemaned66ff92019-05-02 15:30:02 -050011Resource ../resources/json_templater.robot
DR695Hccff30b2017-02-17 18:44:24 -050012
13*** Variables ***
14${MR_HEALTH_CHECK_PATH} /topics
Brian Freeman19a4d2d2018-11-30 13:03:52 -050015${MR_PUB_HEALTH_CHECK_PATH} /events/TEST_TOPIC
16${MR_SUB_HEALTH_CHECK_PATH} /events/TEST_TOPIC/g1/c4?timeout=5000
Brian Freemaned66ff92019-05-02 15:30:02 -050017${MR_CREATE_TOPIC_PATH} /topics/create
18${MR_UPDATE_ACL_TOPIC_PATH} /topics/TEST_TOPIC_ACL/producers
Jerry Flood8fd592b2017-07-29 07:31:50 -040019${MR_ENDPOINT} ${GLOBAL_MR_SERVER_PROTOCOL}://${GLOBAL_INJECTED_MR_IP_ADDR}:${GLOBAL_MR_SERVER_PORT}
Brian Freeman19a4d2d2018-11-30 13:03:52 -050020${MR_PUBLISH_TEMPLATE} robot/assets/templates/mr_publish.template
Brian Freemaned66ff92019-05-02 15:30:02 -050021${MR_PUT_ACL_TEMPLATE} robot/assets/templates/mr_put_acl.template
DR695Hbf5a3a32017-06-30 13:09:57 -040022
DR695Hccff30b2017-02-17 18:44:24 -050023
24*** Keywords ***
25Run MR Health Check
26 [Documentation] Runs MR Health check
Jerry Flood8fd592b2017-07-29 07:31:50 -040027 ${resp}= Run MR Get Request ${MR_HEALTH_CHECK_PATH}
Brian Freeman19a4d2d2018-11-30 13:03:52 -050028 Should Be Equal As Strings ${resp.status_code} 200
DR695Hccff30b2017-02-17 18:44:24 -050029 Should Contain ${resp.json()} topics
Jerry Flood8fd592b2017-07-29 07:31:50 -040030
Brian Freeman19a4d2d2018-11-30 13:03:52 -050031Run MR PubSub Health Check
32 [Documentation] Runs MR PubSub Health check
Brian Freemana8ceb692019-03-03 09:37:54 -050033 #${resp}= Run MR Get Request ${MR_SUB_HEALTH_CHECK_PATH}
Brian Freeman19a4d2d2018-11-30 13:03:52 -050034 # topic may not be created which is a 400 error
Brian Freemana8ceb692019-03-03 09:37:54 -050035
Brian Freeman19a4d2d2018-11-30 13:03:52 -050036 ${resp}= Run MR Post Request ${MR_PUB_HEALTH_CHECK_PATH}
37 Should Be Equal As Strings ${resp.status_code} 200
38 Should Contain ${resp.json()} serverTimeMs Failed to Write Data
39 ${resp}= Run MR Get Request ${MR_SUB_HEALTH_CHECK_PATH}
Brian Freemana8ceb692019-03-03 09:37:54 -050040 # Always Write twice to catch lost first message
41 ${resp}= Run MR Post Request ${MR_PUB_HEALTH_CHECK_PATH}
42 ${resp}= Run MR Get Request ${MR_SUB_HEALTH_CHECK_PATH}
Brian Freeman19a4d2d2018-11-30 13:03:52 -050043 # ${resp} is an array
44 Should Be Equal As Strings ${resp.status_code} 200
45 Should Contain ${resp.json()[0]} timestamp Failed to Read Data
46
Brian Freemaned66ff92019-05-02 15:30:02 -050047
48Run MR Update Topic Acl
49 [Documentation] Runs MR create topic and update producer credentials
50 #
51 # Testing to Delete a Topic:
52 # /opt/kafka/bin/kafka-topics.sh --zookeeper message-router-zookeeper:2181 --delete --topic <topic_name>
53 # /opt/kafka/bin/kafka-topics.sh --zookeeper message-router-zookeeper:2181 --delete --topic TEST_TOPIC_ACL
54 #
55 # Appears to not care if topic already exists with the POST / PUT method
56 #
57 ${dict}= Create Dictionary TOPIC_NAME=TEST_TOPIC_ACL
58 ${data}= Fill JSON Template File ${MR_PUT_ACL_TEMPLATE} ${dict}
59 #Log To Console ${\n}Create TEST_TOPIC_ACL
60 ${resp}= Run MR Auth Post Request ${MR_CREATE_TOPIC_PATH} iPIxkpAMI8qTcQj8 Ehq3WyT4bkif4zwgEbvshGal ${data}
61 #Log To Console Update Owner for TEST_TOPIC_ACL
62 ${resp}= Run MR Auth Put Request ${MR_UPDATE_ACL_TOPIC_PATH}/iPIxkpAMI8qTcQj8 iPIxkpAMI8qTcQj8 Ehq3WyT4bkif4zwgEbvshGal ${data}
63 Should Be Equal As Strings ${resp.status_code} 200
64
65Run MR Auth Post Request
66 [Documentation] Runs MR Authenticated Post Request
67 [Arguments] ${data_path} ${id_key} ${secret_key} ${data}
68 ${current_time}= Get Time
69 ${time}= Evaluate datetime.datetime.today().replace(tzinfo=pytz.UTC).replace(microsecond=0).isoformat() modules=datetime,pytz
70 ${command}= Set Variable /bin/echo -n "${time}" | /usr/bin/openssl sha1 -hmac "${secret_key}" -binary | /usr/bin/openssl base64
71 ${result}= Run Process ${command} shell=True
72 ${signature}= Set Variable ${result.stdout}
73 ${xAuth}= Set Variable ${id_key}:${signature}
74 ${headers}= Create Dictionary Content-Type=application/json X-CambriaAuth=${xAuth} X-CambriaDate=${time}
75 ${session}= Create Session mr ${MR_ENDPOINT}
76 ${resp}= Post Request mr ${data_path} headers=${headers} data=${data}
77 ${status_string}= Convert To String ${resp.status_code}
78 Should Match Regexp ${status_string} ^(204|200)$
79 Log Received response from message router ${resp.text}
80 [Return] ${resp}
81
82
83Run MR Auth Put Request
84 [Documentation] Runs MR Authenticated Put Request
85 [Arguments] ${data_path} ${id_key} ${secret_key} ${data}
86 ${current_time}= Get Time
87 ${time}= Evaluate datetime.datetime.today().replace(tzinfo=pytz.UTC).replace(microsecond=0).isoformat() modules=datetime,pytz
88 ${command}= Set Variable /bin/echo -n "${time}" | /usr/bin/openssl sha1 -hmac "${secret_key}" -binary | /usr/bin/openssl base64
89 ${result}= Run Process ${command} shell=True
90 ${signature}= Set Variable ${result.stdout}
91 ${xAuth}= Set Variable ${id_key}:${signature}
92 ${headers}= Create Dictionary Content-Type=application/json X-CambriaAuth=${xAuth} X-CambriaDate=${time}
93 ${session}= Create Session mr ${MR_ENDPOINT}
94 ${resp}= Put Request mr ${data_path} headers=${headers} data=${data}
95 Should Be Equal As Strings ${resp.status_code} 200
96 Log Received response from message router ${resp.text}
97 [Return] ${resp}
98
DR695Hccff30b2017-02-17 18:44:24 -050099Run MR Get Request
100 [Documentation] Runs MR Get request
101 [Arguments] ${data_path}
Brian Freeman19a4d2d2018-11-30 13:03:52 -0500102 ${session}= Create Session mr ${MR_ENDPOINT}
DR695Hccff30b2017-02-17 18:44:24 -0500103 ${uuid}= Generate UUID
104 ${headers}= Create Dictionary Accept=application/json Content-Type=application/json X-TransactionId=${GLOBAL_APPLICATION_ID}-${uuid} X-FromAppId=${GLOBAL_APPLICATION_ID}
Brian Freeman19a4d2d2018-11-30 13:03:52 -0500105 ${resp}= Get Request mr ${data_path} headers=${headers}
106 Log Received response from message router ${resp.text}
107 [Return] ${resp}
108
109Run MR Post Request
110 [Documentation] Runs MR Post request
111 [Arguments] ${data_path}
112 ${session}= Create Session mr ${MR_ENDPOINT}
113 ${timestamp}= Get Current Date
114 ${dict}= Create Dictionary timestamp=${timestamp}
115 ${data}= Fill JSON Template File ${MR_PUBLISH_TEMPLATE} ${dict}
116 ${uuid}= Generate UUID
117 ${headers}= Create Dictionary Accept=application/json Content-Type=application/json X-TransactionId=${GLOBAL_APPLICATION_ID}-${uuid} X-FromAppId=${GLOBAL_APPLICATION_ID}
118 ${resp}= Post Request mr ${data_path} data=${data} headers=${headers}
DR695Hccff30b2017-02-17 18:44:24 -0500119 Log Received response from message router ${resp.text}
120 [Return] ${resp}
121