File: test_client.py

package info (click to toggle)
python-aiohasupervisor 0.3.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 932 kB
  • sloc: python: 4,666; sh: 37; makefile: 3
file content (24 lines) | stat: -rw-r--r-- 789 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
"""Tests for client."""

import pytest

from aiohasupervisor.client import _SupervisorClient
from aiohasupervisor.exceptions import SupervisorError

from .const import SUPERVISOR_URL


@pytest.mark.parametrize("method", ["get", "post", "put", "delete"])
async def test_path_manipulation_blocked(method: str) -> None:
    """Test path manipulation prevented."""
    client = _SupervisorClient(SUPERVISOR_URL, "abc123", 10)
    action = getattr(client, method)
    with pytest.raises(SupervisorError):
        # absolute path
        await action("/test/../bad")
    with pytest.raises(SupervisorError):
        # relative path
        await action("test/../bad")
    with pytest.raises(SupervisorError):
        # relative path with percent encoding
        await action("test/%2E%2E/bad")