Exemple #1
0
    def test_success(self) -> None:
        add_token("admin", "desc0")

        add_server("10.0.0.1", 11, "ssh-rsa data", 1)
        add_server("10.0.0.2", 22, "ecdsa-sha2-nistp521 data", 1)
        add_server("10.0.0.3", 33, "ssh-ed25519 data", 1)
        self.assertEqual(len(get_servers()), 3)

        delete_server(2)

        servers = get_servers()
        self.assertEqual(len(servers), 2)
        self.assertEqual(servers[0].ip, "10.0.0.1")
        self.assertEqual(servers[1].ip, "10.0.0.3")
Exemple #2
0
    def test_ip(self) -> None:
        add_token("server", "desc")
        add_server("ip1", 1111, "ssh-rsa data comment", 1)
        add_server("ip2", 2222, "ssh-ed25519 data comment", 1)

        servers = get_servers(ip="ip1")
        self.assertEqual(len(servers), 1)
        self.assertEqual(servers[0].ip, "ip1")
Exemple #3
0
    def test_strip_key(self) -> None:
        add_token("server", "desc")
        add_server("ip", 1234, "   ssh-rsa    data     comment    \n\n\n", 1)

        servers = get_servers()
        self.assertEqual(servers[0].key_type, "ssh-rsa")
        self.assertEqual(servers[0].key_data, "data")
        self.assertEqual(servers[0].key_comment, "comment")
Exemple #4
0
    def test_all(self) -> None:
        add_token("server", "desc")

        for i in range(10):
            add_server("ip", i, "ssh-rsa data comment", 1)

        servers = get_servers()
        self.assertEqual(len(servers), 10)
Exemple #5
0
    def test_invalid_id(self) -> None:
        with self.assertRaises(ServerError):
            delete_server(0)

        add_token("admin", "desc")
        add_server("10.0.0.1", 1234, "ssh-rsa data", 1)
        add_server("10.0.0.2", 4321, "ssh-rsa data", 1)

        with self.assertRaises(ServerError):
            delete_server(0)

        self.assertEqual(len(get_servers()), 2)
Exemple #6
0
    def test_success(self) -> None:
        add_token("server", "desc")
        add_server("ip", 1234, "ssh-rsa data comment", 1)

        servers = get_servers()
        self.assertEqual(len(servers), 1)
        self.assertEqual(servers[0].ip, "ip")
        self.assertEqual(servers[0].port, 1234)
        self.assertEqual(servers[0].key_type, "ssh-rsa")
        self.assertEqual(servers[0].key_data, "data")
        self.assertEqual(servers[0].key_comment, "comment")
        self.assertEqual(servers[0].token_id, 1)
Exemple #7
0
    def test_success_admin(self) -> None:
        headers = {
            "Authorization": "Bearer {}".format(add_token("admin", "desc")),
        }

        data = {
            "public_key": "ecdsa-sha2-nistp384 data1234 comment321",
        }

        res = self.client.post("/api/v1/server", headers=headers, data=data)
        obj = json.loads(res.data.decode("utf-8"))
        self.assertEqual(obj["message"], "added")
        self.assertEqual(res.status_code, 200)

        servers = get_servers()
        self.assertEqual(len(servers), 1)
        self.assertEqual(servers[0].key_type, "ecdsa-sha2-nistp384")
        self.assertEqual(servers[0].key_data, "data1234")
        self.assertEqual(servers[0].key_comment, "comment321")