Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web API: Endpoint does not work when identifier contains space #7552

Open
tdesveaux opened this issue May 2, 2024 · 1 comment
Open

Web API: Endpoint does not work when identifier contains space #7552

tdesveaux opened this issue May 2, 2024 · 1 comment

Comments

@tdesveaux
Copy link
Contributor

I setup a reproduction unit test here: https://github.com/tdesveaux/buildbot/tree/tds/api_space_identifier_issue

I found this issue while writing a script to get a Build's logs. Some of the steps names contained spaces and I was getting 404 when querying their log with /builders/n:builderid/builds/n:build_number/steps/i:step_name/logs/i:log_slug/raw.

I also reproduced the issue by creating a master, and changing the Builder name from runtests to run tests /.
checkconfig didn't complain, running the master and a build worked fine.
However, a query on /api/v2/builders/run+tests+%2F results in {"error": "Invalid path: builders/run+tests+/"}.

It looks like the issue is due to the data api using the Identifier to validate the arguments, which does not allow spaces and other characters. But Builder.name, BuildStep.name (and probably others) which are used as identifiers are not validated at config time to bring up the issue.

I'm unsure how to proceed to fix this.
Either, check that any field that can be used as an API identifier is valid, which can be tricky if some of them are renderered (fail checkconfig, log a warn at runtime?).
Or make the API accept identifiers which contains any string.

@tdesveaux
Copy link
Contributor Author

I looked a bit more into this and I'm getting contradicting information.

In DB, Builder's name has no restrictions:

sa.Column('name', sa.Text, nullable=False),

There is restriction on size or characters in the config either:

if not name or type(name) not in (bytes, str):
error("builder's name is required")
name = '<unknown>'
elif name[0] == '_' and name not in RESERVED_UNDERSCORE_NAMES:
error(f"builder names must not start with an underscore: '{name}'")
try:
self.name = bytes2unicode(name, encoding="ascii")
except UnicodeDecodeError:
error("builder names must be unicode or ASCII")

There is even tests that lead to a broken data-api:

def test_unicode_name(self):
cfg = BuilderConfig(name='a \N{SNOWMAN} c', workername='a', factory=self.factory)
self.assertIdentical(cfg.factory, self.factory)
self.assertAttributes(cfg, name='a \N{SNOWMAN} c')

The only place that seam to put restriction on a builder's name is the data-api here:

name = types.Identifier(70)

(which make it validate that a builder name's length it less than 70 and match this regex: ^[a-zA-Z_-][a-zA-Z0-9._-]*$

There is a mention of limiting the buildername length in #3957 to avoid breaking the UI.
If that's the only reason, it should be up to the UI to correctly handle longer names, not the API. The UI is not the only client of the API (this break accessing these builders with Rest and probably GraphQL as well).

I updated my branch with an even clearer reproduction: master...tdesveaux:buildbot:tds/api_space_identifier_issue#diff-91b181695ef480960bcd9482cd44a4cd1408038053e86ec7924cedd71881871d

Using the same buildername used in the config.test_builder.py unicode test (which is considered valid), accessing the builder by name with the data api fails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant