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

Question: should we even allow a request when replacements aren't done? #25

Closed
vsoch opened this issue Oct 17, 2020 · 1 comment
Closed

Comments

@vsoch
Copy link
Contributor

vsoch commented Oct 17, 2020

There is a test that expects raising an error because the <reference> is not defined, and I can indeed reproduce this because the url turns out to be:

http://localhost:58747/v2/othername/manifests/<reference>

Of course this works fine, but it's done via trying and failing because the url is weird. I'm wondering if we might want to do checks first to see if replacements haven't been done, and raise an error before doing any request. For example in Python:

# would match if we forgot to fill in a replacement for a template string
re.search('<.+>', req.url)

The current client doesn't do any checks to see if replacements aren't defined.

I'll leave the reggie-python version to match this one for the time being, and we can possibly update both if it seems like a good idea.

@vsoch
Copy link
Contributor Author

vsoch commented Oct 17, 2020

Ah hold the phone! The validation is already there, I somehow forgot this since yesterday and today 👍

def validateRequest(req):
    """Ensure that we have no unfilled template strings"""
    regex = re.compile("<name>|<reference>|<digest>|<session_id>|//{2,}")
    if not req.url:
        raise ValueError("A url is required to prepare a request.")

    if not req.method:
        raise ValueError("A method is required to prepare a request")

    if regex.search(req.url):
        raise ValueError("request is invalid")`

@vsoch vsoch closed this as completed Oct 17, 2020
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