-
Notifications
You must be signed in to change notification settings - Fork 50
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
FOGL-8753 : Implemented user blocking for incorrect password #1397
Conversation
Signed-off-by: nandan <nandan.ghildiyal@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dry run review!
Unit tests are failing and good to have new tests for existing API as user update have been touched!
if int(user_id) == 1: | ||
msg = "Restricted for Super Admin user." | ||
_logger.warning(msg) | ||
raise web.HTTPForbidden(reason=msg, body=json.dumps({"message": msg})) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we block Super Admin user? I believe NO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No we do not currently. We should make this any user with admin right in future and allowing blocking of admin users as long as there is always one unblocked admin user. This is not for the current change however.
['id', '=', user_id]).payload() | ||
storage_client = connect.get_storage_async() | ||
old_result = await storage_client.query_tbl_with_payload('users', payload) | ||
if len(old_result['rows']) == 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If 'rows' Key is not available then? raise Storage Server Exception
@@ -602,6 +602,8 @@ CREATE TABLE fledge.users ( | |||
enabled boolean NOT NULL DEFAULT TRUE, | |||
pwd_last_changed timestamp(6) with time zone NOT NULL DEFAULT now(), | |||
access_method character varying(5) CHECK( access_method IN ('any','pwd','cert') ) NOT NULL DEFAULT 'any', | |||
failed_attempts integer DEFAULT 0, | |||
block_until timestamp(6) DEFAULT now(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with timezone?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably best tp use etc as the user might change timezones, especially should not be based on the timezone of the caller of the API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MarkRiddoch While login user can only provide id and password. There is no way user can provide any information related to time. API does all the calculation for block time on the basis of information stored into the database. So we are safe here even if user changes timezone. so is it good now?
Signed-off-by: nandan <nandan.ghildiyal@gmail.com>
Signed-off-by: nandan <nandan.ghildiyal@gmail.com>
Signed-off-by: nandan <nandan.ghildiyal@gmail.com>
Signed-off-by: nandan <nandan.ghildiyal@gmail.com>
Signed-off-by: nandan <nandan.ghildiyal@gmail.com>
Signed-off-by: nandan <nandan.ghildiyal@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good - we should probably address the timezone issue however.
@@ -602,6 +602,8 @@ CREATE TABLE fledge.users ( | |||
enabled boolean NOT NULL DEFAULT TRUE, | |||
pwd_last_changed timestamp(6) with time zone NOT NULL DEFAULT now(), | |||
access_method character varying(5) CHECK( access_method IN ('any','pwd','cert') ) NOT NULL DEFAULT 'any', | |||
failed_attempts integer DEFAULT 0, | |||
block_until timestamp(6) DEFAULT now(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably best tp use etc as the user might change timezones, especially should not be based on the timezone of the caller of the API.
Signed-off-by: nandan <nandan.ghildiyal@gmail.com>
Audit API tests are also failing with the given change |
VERSION file is also missing. It should be with version 72 |
…atus Signed-off-by: nandan <nandan.ghildiyal@gmail.com>
Signed-off-by: nandan <nandan.ghildiyal@gmail.com>
@@ -1,4 +1,5 @@ | |||
ALTER TABLE fledge.users ADD COLUMN failed_attempts INTEGER DEFAULT 0; | |||
ALTER TABLE fledge.users ADD COLUMN block_until DATETIME DEFAULT "2024-01-01 10:10:10.55"; | |||
ALTER TABLE fledge.users ADD COLUMN block_until DATETIME DEFAULT NULL; | |||
UPDATE fledge.users SET block_until=current_timestamp; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sqlite: CURRENT_TIMESTAMP is in GMT, not the timezone of the machine.
UPDATE users SET block_until=(SELECT STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW', 'localtime'))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we not setting null? TS should be only if blocked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please resolve timezone issue and then I think this is probably ok
…l to NULL Signed-off-by: nandan <nandan.ghildiyal@gmail.com>
Signed-off-by: nandan <nandan.ghildiyal@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine, ideally address comments from Ashish before checkin
Signed-off-by: nandan <nandan.ghildiyal@gmail.com>
Signed-off-by: nandan <nandan.ghildiyal@gmail.com>
raise web.HTTPForbidden | ||
|
||
user_id = request.match_info.get('user_id') | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type cast of user_id only once
if datetime.strptime(block_until, DATE_FORMAT) > datetime.strptime(curr_time, DATE_FORMAT): | ||
diff = datetime.strptime(block_until, DATE_FORMAT) - datetime.strptime(curr_time, DATE_FORMAT) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
block_until_datetime_formatter = datetime.strptime(block_until, DATE_FORMAT)
current_datetime_formatter = datetime.strptime(curr_time, DATE_FORMAT)
hours_left = "" | ||
if hours == 1 : | ||
hours_left = "{} hour ".format(hours) | ||
elif hours > 1: | ||
hours_left = "{} hours ".format(hours) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hours_left = "{} hour ".format(hours) if hours == 1 else "{} hours ".format(hours)
minutes_left = " 1 minute" #Show minutes 1 or less than 1 as "1 minute" | ||
if minutes > 1: | ||
minutes_left = " {} minutes ".format(minutes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can also be break into single statement
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review done!
No description provided.