devopshq / teamcity

dohq-teamcity is a Python package providing access to the JetBrains TeamCity server API.
https://devopshq.github.io/teamcity/
MIT License
33 stars 12 forks source link

Default empty value of Configuration.safe_chars_for_path_param seems wrong #26

Open kapsh opened 4 years ago

kapsh commented 4 years ago

Reproducible example (using https://teamcity.jetbrains.com/viewType.html?buildTypeId=DemoProjects_TeamCity_Net_Build for build having artifacts):

import dohq_teamcity, logging

logging.basicConfig(level=logging.DEBUG)
logging.getLogger("urllib3").setLevel(logging.DEBUG)
teamcity = dohq_teamcity.TeamCity("https://teamcity.jetbrains.com/guestAuth", auth=None)
build = teamcity.builds.get("buildType:(id:DemoProjects_TeamCity_Net_Build),number:8")
build.get_children("/Clock.Console/linux-x64")

Result:

"HTTP Status 400 – Bad Request". It can be seen in debug log that request has been made to URL /guestAuth/app/rest/builds/id%3A3101739/artifacts/children%2FClock.Console%2Flinux-x64 which is obviously wrong: / should not be escaped in artifacts paths. Relevant part from swagger.json:

  /app/rest/builds/{buildLocator}/artifacts/children{path}:
    get:
      tags:
      - Build
      operationId: getChildren
      parameters:
      - name: path
        in: path
        required: true
        type: string
        pattern: (/.*)?

After setting teamcity.configuration.safe_chars_for_path_param = "/" (default value was empty string) URL in request becomes correct /guestAuth/app/rest/builds/id%3A3101739/artifacts/children/Clock.Console/linux-x64 (method call still requires workaround from #25 to work completely).

Suggestion would be to set Configuration.safe_chars_for_path_param to / by default, though it's not clear what other parts this can break.