source: ogServer-Git/tests/units/test_0004_post_shell_run.py @ a801e78

Last change on this file since a801e78 was 1cdbc5f, checked in by OpenGnSys Support Team <soporte-og@…>, 5 years ago

#915 Test malformed payload for POST /shell/run

This test covers requests that do not contain 1 of the parameters in their
payloads.

  • Property mode set to 100644
File size: 1.2 KB
RevLine 
[5312e73]1import requests
2import unittest
3
4class TestPostShellRunMethods(unittest.TestCase):
5
6    def setUp(self):
7        self.url = 'http://localhost:8888/shell/run'
[eae2385]8        self.headers = {'Authorization' : '07b3bfe728954619b58f0107ad73acc1'}
[ee2e16a]9        self.json = { 'clients' : [ '192.168.2.1', '192.168.2.2' ],
10                      'run' : 'ls',
11                      'echo': True}
[eae2385]12
[5312e73]13    def test_post(self):
[eae2385]14        returned = requests.post(self.url, headers=self.headers, json=self.json)
[5312e73]15        self.assertEqual(returned.status_code, 200)
16
[65cc7c1]17    def test_no_payload(self):
18        returned = requests.post(self.url, headers=self.headers, json=None)
19        self.assertEqual(returned.status_code, 400)
20
[1cdbc5f]21    def test_malformed_payload(self):
22        for parameter in self.json:
23            malformed_payload = self.json.copy()
24            malformed_payload.pop(parameter)
25            returned = requests.post(self.url,
26                                     headers=self.headers,
27                                     json=malformed_payload)
28            self.assertEqual(returned.status_code, 400)
29
[5312e73]30    def test_get(self):
[55edb40]31        returned = requests.get(self.url, headers=self.headers)
32        self.assertEqual(returned.status_code, 405)
[5312e73]33
34if __name__ == '__main__':
35    unittest.main()
Note: See TracBrowser for help on using the repository browser.