Fix/create temp url escaping#1994
Fix/create temp url escaping#1994jtopjian merged 14 commits intogophercloud:masterfrom Lirt:fix/create-temp-url-escaping
Conversation
- #1993 - URL MUST NOT be encoded prior to hashing - From Swift docs - Do not URL-encode the path when you generate the HMAC-SHA1 signature Signed-off-by: Ondrej Vasko <ondrej.vaskoo@gmail.com>
|
For tests to work, time.Now() in function I know that time cannot be mocked, but there are other techniques that could be done. Can you help me with this @kayrus? Also let me know what you think about this approach to unit test. If you think we can test this easier, I can rewrite it. Edit: Also I can add one more test with slashes in object name (which caused the original issue) |
- This test should generate URL with consistent signature and expiry and then be asserted Signed-off-by: Ondrej Vasko <ondrej.vaskoo@gmail.com>
|
Build succeeded.
|
I'd split this func and use the major logic func in unit tests. I wonder how terraform functional tests passed this, and noticed that object name doesn't contain the slash: https://github.com/terraform-providers/terraform-provider-openstack/blob/152286f9ae3d016cb38d53ae2c0d1920d967d368/openstack/resource_openstack_objectstorage_tempurl_v1_test.go#L14 |
Signed-off-by: Ondrej Vasko <ondrej.vaskoo@gmail.com>
This gives enough flexibility to stub time and perform unit tests Signed-off-by: Ondrej Vasko <ondrej.vaskoo@gmail.com>
Signed-off-by: Ondrej Vasko <ondrej.vaskoo@gmail.com>
Signed-off-by: Ondrej Vasko <ondrej.vaskoo@gmail.com>
I'm sorry, but I don't see way how to split it and use it without adding new argument for What I came up after some research is allowing to change function of time at package level (https://labs.yulrizka.com/en/stubbing-time-dot-now-in-golang/) - f4b9e4b. Feel free to update the MR with how you see it. |
…added Signed-off-by: Ondrej Vasko <ondrej.vaskoo@gmail.com>
|
Build failed.
|
| } | ||
| duration := time.Duration(opts.TTL) * time.Second | ||
| expiry := time.Now().Add(duration).Unix() | ||
| expiry := timeNow().Add(duration).Unix() |
There was a problem hiding this comment.
I wonder how did it work before without UTC()
There was a problem hiding this comment.
Good question, I didn't think about that. I was reading docs, and it says Unix() should be consistent in any way ⬇️.
Unix()The result does not depend on the location associated with t. Unix-like operating systems
https://golang.org/pkg/time/#Time.Unix
So I can actually revert back to Now() if it looks better for you.
There was a problem hiding this comment.
There was a problem hiding this comment.
Not sure what should be used. @jtopjian please advice.
There was a problem hiding this comment.
Can we resolve as discussed below?
It was commited here 9a500de
|
Build succeeded.
|
Signed-off-by: Ondrej Vasko <ondrej.vaskoo@gmail.com>
|
Build succeeded.
|
|
Build succeeded.
|
Signed-off-by: Ondrej Vasko <ondrej.vaskoo@gmail.com>
|
Build succeeded.
|
|
Had to fix some issues with Time packaging, but it works now correctly. Question is if this way is OK for you maintainers. As I said I didn't find better solution yet, but I am open to suggestions. I will also add 1 integration test, to cover this function better, but I think it will take some time, since it will be my first. |
Signed-off-by: Ondrej Vasko <ondrej.vaskoo@gmail.com>
|
Build failed.
|
|
|
||
| resp, err := http.Get(objURLs[i]) | ||
| th.AssertNoErr(t, err) | ||
| defer resp.Body.Close() |
There was a problem hiding this comment.
not critical, but better to call resp.Body.Close() at the end of the loop. otherwise go will close the connection only when the test function exits.
Signed-off-by: Ondrej Vasko <ondrej.vaskoo@gmail.com>
Signed-off-by: Ondrej Vasko <ondrej.vaskoo@gmail.com>
| Split string | ||
| } | ||
|
|
||
| type nowFuncT func() time.Time |
There was a problem hiding this comment.
What if add the date into the CreateTempURLOpts struct? If it is nil, then a default time.Now() is used. If not, the provided value is used. This will avoid hacking around the ResetClockImplementation
There was a problem hiding this comment.
There was a problem hiding this comment.
Please check 9a500de
Notice I didn't use pointer to time.Time because as documentation says:
Programs using times should typically store and pass them as values, not pointers. That is, time variables and struct fields should be of type time.Time, not *time.Time.
But I used isZero() to check for null value.
There was a problem hiding this comment.
I looks much cleaner when passing time as opts :-)
- This way is less hacky than packaging time Signed-off-by: Ondrej Vasko <ondrej.vaskoo@gmail.com>
|
Build failed.
|
Signed-off-by: Ondrej Vasko <ondrej.vaskoo@gmail.com>
|
Build failed.
|
|
Acceptance test for the function was successful, but some other failed, doing recheck. |
|
recheck |
|
Build failed.
|
|
@kayrus Can you please look at the pipeline? I'm not sure if I should just run recheck, or there is something wrong. I think it is failing on something different than my code. 2020-08-03 10:06:35.176116 | ubuntu-bionic | --- SKIP: TestMessageDelete (0.19s)
2020-08-03 10:06:35.176174 | ubuntu-bionic | messages_test.go:91: No messages were found
2020-08-03 10:06:35.176219 | ubuntu-bionic | PASS
2020-08-03 10:06:35.177855 | ubuntu-bionic | ok github.com/gophercloud/gophercloud/acceptance/openstack/sharedfilesystems/v2/messages 0.531s
2020-08-03 10:06:35.201255 | ubuntu-bionic | + ./script/acceptancetest:main:101 : [[ 0 != 0 ]]
2020-08-03 10:06:35.204759 | ubuntu-bionic | + ./script/acceptancetest:main:107 : [[ -n 1 ]]
2020-08-03 10:06:35.206948 | ubuntu-bionic | + ./script/acceptancetest:main:108 : exit 1
2020-08-03 10:06:39.396148 | ubuntu-bionic | ERROR
2020-08-03 10:06:39.397095 | ubuntu-bionic | {
2020-08-03 10:06:39.397221 | ubuntu-bionic | "delta": "0:45:12.849894",
2020-08-03 10:06:39.397348 | ubuntu-bionic | "end": "2020-08-03 10:06:38.006579",
2020-08-03 10:06:39.397430 | ubuntu-bionic | "msg": "non-zero return code",
2020-08-03 10:06:39.397508 | ubuntu-bionic | "rc": 1,
2020-08-03 10:06:39.397628 | ubuntu-bionic | "start": "2020-08-03 09:21:25.156685"
2020-08-03 10:06:39.397715 | ubuntu-bionic | } |
|
recheck |
|
Build failed.
|
|
The acceptance test failure should be fixed when #2000 is merged. |
|
@jtopjian Thank you. I'm pretty much done with this MR. You can do review when you have time for it. |
For #1993
Fix issue with generating temporary URLs, which are invalid when conatiner or object name contains characters, which are subject to query escaping.