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

feat(basic-auth) don't trim whitespace from basic-auth passwords #3650

Closed
wants to merge 2 commits into from
Closed

feat(basic-auth) don't trim whitespace from basic-auth passwords #3650

wants to merge 2 commits into from

Conversation

aloisbarreras
Copy link
Contributor

  • adding option to basic-auth schema to disable trimming whitespace from
    password.
  • adding test

fix #3595

Copy link
Member

@thibaultcha thibaultcha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @aloisbarreras

Thank you for the patch! I left a couple of tests-centric notes that we'd need you to address, please :)

@@ -77,6 +77,30 @@ for _, strategy in helpers.each_strategy() do
}
assert.equal(hash, json.password)
end)
it("encrypts the password without trimming whitespace #only", function()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove the #only tag in this test's title?

@@ -127,7 +127,9 @@ function _M.validate_entity(tbl, schema, options)
local is_valid_type
-- ALIASES: number, timestamp, boolean and array can be passed as strings and will be converted
if type(t[column]) == "string" then
t[column] = utils.strip(t[column])
if schema.fields[column].trim_whitespace ~= false then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would also need unit tests or two in the plugins' validator test suite for this new field option, please. Especially since we use a false comparison vs. falsy (which is a good call)!

@thibaultcha thibaultcha added the pr/changes requested Changes were requested to this PR by a maintainer. Please address them and ping back once done. label Jul 27, 2018
@aloisbarreras
Copy link
Contributor Author

I removed the #only tag (whoops 😄) and added some tests. Let me know how it looks

Copy link
Member

@thibaultcha thibaultcha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aloisbarreras Thanks!

assert.are.same("kong", values.string)
end)
it("should trim whitepsace from value with trim_whitespace = true", function()
local trimSchema = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a nitpick, but can we use snake_case instead for these? Thanks in advance :)

There are a few typos in the tests name that we can fix ourselves before merging too, no worries.

@@ -25,7 +25,7 @@ local SCHEMA = {
created_at = {type = "timestamp", immutable = true, dao_insert_value = true},
consumer_id = {type = "id", required = true, foreign = "consumers:id"},
username = {type = "string", required = true, unique = true },
password = {type = "string", func = encrypt_password}
password = {type = "string", func = encrypt_password, trim_whitespace = false}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if your PR was updated to have two commits:

  1. Adding support (+ unit tests) for the trim_whitespace attribute in the schema validator
  2. Adding the trim_whitespace attribute to the basic-auth schema (+ tests)

As per our contributing guidelines, we try to respect strict atomicity in our commits :)

Thanks!

@aloisbarreras
Copy link
Contributor Author

Ah crap. Yeah I was just being sloppy. Thanks for being patient.

Now we should be good to go.


local values = {string = " kong "}

local valid, err = validate_entity(values, trimSchema)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your patch is now failing to lint/pass CI (https://travis-ci.org/Kong/kong/jobs/409120621), because the name was not updated here and in the below test

@aloisbarreras
Copy link
Contributor Author

Haha alright I swear I'm normally more careful than that. I was coding on an airplane and rushing to get done before I landed.

Anyway, now we're really good to go. Linting is good, all tests are passing, and commits are atomic.

@thibaultcha thibaultcha added pr/please review and removed pr/changes requested Changes were requested to this PR by a maintainer. Please address them and ping back once done. labels Jul 31, 2018
thibaultcha pushed a commit that referenced this pull request Aug 1, 2018
@thibaultcha
Copy link
Member

thibaultcha commented Aug 1, 2018

Awesome, merged! Thanks a lot for your contribution!

Reminder: as a Kong contributor, you can now receive your own Contributor T-shirt by claiming it :)

@thibaultcha thibaultcha closed this Aug 1, 2018
@aloisbarreras aloisbarreras deleted the feat/basicauth-password-no-trim-whitespace branch August 1, 2018 20:17
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

Successfully merging this pull request may close these issues.

Don't strip whitespace on passwords
2 participants