-
Notifications
You must be signed in to change notification settings - Fork 95
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
OBG-442 Date formatting problem solved and deny consent redirects done #605
Conversation
@@ -61,7 +62,7 @@ export class StorageService { | |||
return null; | |||
} | |||
const date = new Date(parseInt(validUntilTimestamp)); | |||
if (date.toLocaleString() === "Invalid Date") { | |||
if (Consts.toLocaleString(date) === "Invalid Date") { |
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.
Date validity can be checked via:
if(isNaN(date)) {
// handle invalid date
}
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 is better. Thx.
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.
const date = new Date(parseInt(validUntilTimestamp));
if (isNaN(date)) {
return null;
}
Argument of type date is not assignable to parameter of type number.
The weired thing is, that sometimes I got a number, though the localStorage field was empty. And that resulted in a Invalid Date. Unfortunatly I can not reproduce error.
@@ -29,7 +30,7 @@ export class NavbarComponent implements OnInit { | |||
getSessionValidUntil(): string { | |||
const validUntilDate: Date = this.storageService.getValidUntilDate(); | |||
if (validUntilDate != null) { | |||
const validUntilDateString = validUntilDate.toLocaleString(); | |||
const validUntilDateString = Consts.toLocaleString(validUntilDate); |
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.
The entire regex-part of function can be simplified to:
var time = date.toLocaleTimeString('en-GB')
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.
Yes, but I have several places where this is used. I definitly want to have DateFormating handled in one place. Specially, toLoclaTimeString has a second Parameter, we do not use yet.
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.
You can create utility function and use it everywhere
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.
I put uitilty function in consts.ts. It is no more bound to class Consts.
Codecov Report
@@ Coverage Diff @@
## develop #605 +/- ##
=============================================
- Coverage 70.83% 70.41% -0.43%
Complexity 673 673
=============================================
Files 331 332 +1
Lines 3786 3833 +47
Branches 352 357 +5
=============================================
+ Hits 2682 2699 +17
- Misses 905 935 +30
Partials 199 199
Continue to review full report at Codecov.
|
@@ -58,6 +58,11 @@ | |||
|
|||
@Override | |||
public ResponseEntity fromConsentOkGET(String authId, String finTechRedirectCode, UUID xRequestID, String xsrfToken) { | |||
if (!authorizeService.isAuthorized()) { | |||
log.warn("fromConsentOkGET failed: user is not authorized! - path is \"/v1/" + authId + "/fromConsentOk\""); |
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 be done without string concat:
log.warn("fromConsentOkGET failed: user is not authorized! - path is \"/v1/{}/fromConsentOk\"", authId);
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.
done
@@ -29,7 +30,7 @@ export class NavbarComponent implements OnInit { | |||
getSessionValidUntil(): string { | |||
const validUntilDate: Date = this.storageService.getValidUntilDate(); | |||
if (validUntilDate != null) { | |||
const validUntilDateString = validUntilDate.toLocaleString(); | |||
const validUntilDateString = Consts.toLocaleString(validUntilDate); |
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.
You can create utility function and use it everywhere
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED); | ||
} | ||
|
||
if ("ok".equalsIgnoreCase(okOrNotok) && consentService.confirmConsent(authId, xRequestID)) { |
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.
as I understood okOrNotok
is a state of some session. And in this case, the boolean type will be enough in order to recognize 'ok' (true) or notOk
(false) state.
But maybe using an enum as an indicator of state will be preferred. Enum value could be compared with the state without hardcoded string value.
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.
Ok, changed it to enum in api, impl and ui. But api enum is not generated, to I had to create enum value by hand (OpenAPITools/openapi-generator#2834)
@@ -29,7 +30,7 @@ export class NavbarComponent implements OnInit { | |||
getSessionValidUntil(): string { | |||
const validUntilDate: Date = this.storageService.getValidUntilDate(); | |||
if (validUntilDate !== null) { | |||
const validUntilDateString = validUntilDate.toLocaleString(); | |||
const validUntilDateString = toLocaleString(validUntilDate); | |||
const regEx = /.*([0-9]{2}:[0-9]{2}:[0-9]{2})/; |
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 this regex is needed?
var time = date.toLocaleTimeString('en-GB')
will return time in en-GB locale
const date = new Date(parseInt(validUntilTimestamp, 10)); | ||
if (date.toLocaleString() === 'Invalid Date') { | ||
const date = new Date(parseInt(validUntilTimestamp, 0)); | ||
if (toLocaleString(date) === 'Invalid Date') { |
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.
Using this hardcoded literal is really bad. I would advise using date library like moment or luxon for date operations - and I see there are lots of date operations
@@ -16,7 +16,10 @@ export class LoginComponent implements OnInit { | |||
ngOnInit() { | |||
this.loginForm = this.formBuilder.group({ | |||
username: ['', [Validators.required, Validators.pattern('^[a-z0-9]+$')]], | |||
password: ['', [Validators.required, Validators.pattern('.{4}')]] | |||
password: ['', Validators.required] |
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.
Since backend requires 4 character password to register new user - this one was used
String xsrfToken = UUID.randomUUID().toString(); | ||
HttpHeaders authHeaders = authorizeService.modifySessionEntityAndCreateNewAuthHeader(restRequestContext.getRequestId(), sessionEntity, | ||
xsrfToken, cookieConfigProperties, SessionCookieType.REGULAR); | ||
authHeaders.put(LOCATION_HEADER, singletonList(redirectUrls.getOkStatePath())); | ||
authHeaders.put(LOCATION_HEADER, singletonList(redirectUrl)); |
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 not simply authHeaders.set instead of put with list?
No description provided.