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

OBG-442 Date formatting problem solved and deny consent redirects done #605

Merged
merged 11 commits into from
Apr 27, 2020

Conversation

electronicpeter
Copy link
Contributor

No description provided.

@@ -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") {
Copy link
Contributor

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
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is better. Thx.

Copy link
Contributor Author

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);
Copy link
Contributor

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')

Copy link
Contributor Author

@electronicpeter electronicpeter Apr 23, 2020

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.

Copy link
Contributor

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

Copy link
Contributor Author

@electronicpeter electronicpeter Apr 27, 2020

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-io
Copy link

codecov-io commented Apr 23, 2020

Codecov Report

Merging #605 into develop will decrease coverage by 0.42%.
The diff coverage is 41.93%.

Impacted file tree graph

@@              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              
Impacted Files Coverage Δ Complexity Δ
...impl/controller/FinTechAccountInformationImpl.java 45.45% <0.00%> (-10.11%) 3.00 <0.00> (ø)
...sys/opba/fintech/impl/tppclients/HeaderFields.java 0.00% <ø> (ø) 0.00 <0.00> (ø)
...c/app/api/api/finTechAccountInformation.service.ts 40.00% <ø> (ø) 0.00 <0.00> (ø)
...ui/src/app/api/api/finTechAuthorization.service.ts 25.00% <0.00%> (-0.76%) 0.00 <0.00> (ø)
...ch-ui/src/app/api/api/finTechBankSearch.service.ts 32.14% <ø> (ø) 0.00 <0.00> (ø)
...les/fintech-ui/src/app/api/model/accountDetails.ts 100.00% <ø> (ø) 0.00 <0.00> (ø)
.../app/bank/list-accounts/list-accounts.component.ts 37.50% <0.00%> (-1.64%) 0.00 <0.00> (ø)
...app/bank/services/consent-authorization.service.ts 9.09% <0.00%> (ø) 0.00 <0.00> (?)
...ntech-ui/src/app/common/navbar/navbar.component.ts 21.42% <0.00%> (ø) 0.00 <0.00> (ø)
...amples/fintech-ui/src/app/login/login.component.ts 11.11% <ø> (ø) 0.00 <0.00> (ø)
... and 16 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5885a33...d2282b8. Read the comment docs.

@@ -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\"");
Copy link
Contributor

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);

Copy link
Contributor Author

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);
Copy link
Contributor

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

@electronicpeter electronicpeter changed the title OBG-442 Date formatting problem solved OBG-442 Date formatting problem solved and deny consent redirects done Apr 27, 2020
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
}

if ("ok".equalsIgnoreCase(okOrNotok) && consentService.confirmConsent(authId, xRequestID)) {
Copy link
Contributor

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.

Copy link
Contributor Author

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})/;
Copy link
Contributor

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') {
Copy link
Contributor

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]
Copy link
Contributor

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));
Copy link
Contributor

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?

@electronicpeter electronicpeter merged commit 945812c into develop Apr 27, 2020
@electronicpeter electronicpeter deleted the 442-continued branch April 27, 2020 23:07
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.

4 participants