Skip to content

Commit

Permalink
version + cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ebrehault committed Feb 20, 2020
1 parent 38523af commit 9993b19
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 30 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.1.0 (2020-02-20)

- Support full login logic (bloodbare)

# 1.0.3 (2020-01-24)

- Auto-tagging and auto-release to NPM
Expand Down
4 changes: 2 additions & 2 deletions projects/grange-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@guillotinaweb/grange-core",
"version": "1.0.3",
"name": "grange-core",
"version": "1.1.0",
"license": "MIT",
"author": {
"name": "Eric Brehault",
Expand Down
3 changes: 2 additions & 1 deletion projects/grange-core/src/lib/api.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ describe('APIService', () => {
{
provide: 'CONFIGURATION', useValue: {
BACKEND_URL: 'http://fake/Plone',
}}
}},
{ provide: 'LANG', useValue: 'en'},
]
});

Expand Down
11 changes: 7 additions & 4 deletions projects/grange-core/src/lib/authentication.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { HttpErrorResponse, HttpEventType, HttpHeaders } from '@angular/common/http';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { TestBed } from '@angular/core/testing';
import { TestBed, async } from '@angular/core/testing';
import { AuthenticatedStatus, Error, PasswordResetInfo } from './interfaces';
import { AuthenticationService, getError } from './authentication.service';
import { ConfigurationService } from './configuration.service';
import { ReCaptchaV3Service } from './recaptcha_v3.service';
import { filter } from 'rxjs/operators';

describe('AuthenticationService', () => {
beforeEach(() => {
Expand All @@ -12,11 +14,13 @@ describe('AuthenticationService', () => {
providers: [
AuthenticationService,
ConfigurationService,
ReCaptchaV3Service,
{
provide: 'CONFIGURATION', useValue: {
BACKEND_URL: 'http://fake/Plone',
}
},
{ provide: 'LANG', useValue: 'en'},
]
});
});
Expand Down Expand Up @@ -89,15 +93,14 @@ describe('AuthenticationService', () => {
});

it('should logout', () => {
const service = TestBed.get(AuthenticationService);
const service: AuthenticationService = TestBed.get(AuthenticationService);

// fake login
localStorage.setItem('auth', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiZnVsbG5hbWUiOiJGb28gYmFyIiwiZ' +
'XhwaXJlcyI6MTQ2NjE0MDA2Ni42MzQ5ODYsInR5cGUiOiJKV1QiLCJhbGdvcml0aG0iOiJIUzI1NiJ9.D9EL5A9xD1z3E_HPecXA-Ee7kKlljYvpDtan69KHwZ8');
localStorage.setItem('auth_time', (new Date()).toISOString());

service.logout();

service._logout();
expect(localStorage.getItem('auth')).toEqual(null);
expect(localStorage.getItem('auth_time')).toEqual(null);
});
Expand Down
38 changes: 19 additions & 19 deletions projects/grange-core/src/lib/authentication.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {
HttpHeaders,
} from '@angular/common/http';
import { Injectable } from '@angular/core';
import { BehaviorSubject, Observable, from } from 'rxjs';
import { BehaviorSubject, Observable, from, throwError } from 'rxjs';
import { AuthenticatedStatus, Error, PasswordResetInfo, UserInfoTokenParts, LoginToken } from './interfaces';
import { tap, catchError, map, concatMap } from 'rxjs/operators';
import { catchError, map, concatMap } from 'rxjs/operators';
import { ReCaptchaV3Service } from './recaptcha_v3.service';
import { ConfigurationService } from './configuration.service';

Expand Down Expand Up @@ -116,7 +116,7 @@ export class AuthenticationService {

protected error(errorResponse: HttpErrorResponse): Observable<Error> {
const error: Error = getError(errorResponse);
return Observable.throw(error);
return throwError(error);
}

// LOGIN LOGIC
Expand All @@ -129,7 +129,7 @@ export class AuthenticationService {
return this.doLogin(login, password, path, token);
}),
catchError((err) => {
return Observable.throw(err);
return throwError(err);
}));
} else {
return this.doLogin(login, password, path);
Expand Down Expand Up @@ -177,14 +177,14 @@ export class AuthenticationService {
error: error.message,
});
}
return Observable.throw(error);
return throwError(error);
})
);
}

// LOGOUT LOGIC

private _logout() {
_logout() {
this.cleanBasicCredentials();
localStorage.removeItem('auth');
localStorage.removeItem('auth_time');
Expand All @@ -196,7 +196,7 @@ export class AuthenticationService {
const url =
this.config.get('BACKEND_URL') + `/@logout`;
this.http
.post(url, {}, { headers: headers })
.post(url, {}, { headers })
.pipe(
catchError(this.error.bind(this))
).subscribe(
Expand All @@ -216,7 +216,7 @@ export class AuthenticationService {
const url =
this.config.get('BACKEND_URL') + `/@users/${login}/reset-password`;
return this.http
.post(url, {}, { headers: headers })
.post(url, {}, { headers })
.pipe(
catchError(this.error.bind(this))
);
Expand All @@ -227,10 +227,10 @@ export class AuthenticationService {
const promise = this.recaptcha.executeAsPromise(this.config.get('RECAPTCHA_TOKEN'), 'reset');
return from(promise).pipe(
concatMap((token: string) => {
return this.doRequestPasswordReset(login, token)
return this.doRequestPasswordReset(login, token);
}),
catchError((err) => {
return Observable.throw(err);
return throwError(err);
}));
} else {
return this.doRequestPasswordReset(login);
Expand All @@ -254,7 +254,7 @@ export class AuthenticationService {
this.config.get('BACKEND_URL') +
`/@users/${resetInfo.login}/reset-password`;
return this.http
.post(url, data, { headers: headers })
.post(url, data, { headers })
.pipe(
catchError(this.error.bind(this))
);
Expand All @@ -273,7 +273,7 @@ export class AuthenticationService {
this.config.get('BACKEND_URL') +
`/@validate_schema/${token}`;
return this.http
.post(url, {}, { headers: headers })
.post(url, {}, { headers })
.pipe(
catchError(this.error.bind(this))
);
Expand All @@ -284,10 +284,10 @@ export class AuthenticationService {
const promise = this.recaptcha.executeAsPromise(this.config.get('RECAPTCHA_TOKEN'), 'schema');
return from(promise).pipe(
concatMap((recaptcha: string) => {
return this.doGetValidationSchema(token, recaptcha)
return this.doGetValidationSchema(token, recaptcha);
}),
catchError((err) => {
return Observable.throw(err);
return throwError(err);
}));
} else {
return this.doGetValidationSchema(token);
Expand All @@ -300,7 +300,7 @@ export class AuthenticationService {
this.config.get('BACKEND_URL') +
`/@validate/${token}`;
return this.http
.post(url, model, { headers: headers })
.post(url, model, { headers })
.pipe(
catchError(this.error.bind(this))
);
Expand All @@ -312,10 +312,10 @@ export class AuthenticationService {
const promise = this.recaptcha.executeAsPromise(this.config.get('RECAPTCHA_TOKEN'), 'validation');
return from(promise).pipe(
concatMap((recaptcha: string) => {
return this.doRealValidation(token, model, recaptcha)
return this.doRealValidation(token, model, recaptcha);
}),
catchError((err) => {
return Observable.throw(err);
return throwError(err);
}));
} else {
return this.doRealValidation(token, model);
Expand All @@ -327,7 +327,7 @@ export class AuthenticationService {
const url =
this.config.get('BACKEND_URL') + `/@info`;
return this.http
.get(url, { headers: headers })
.get(url, { headers })
.pipe(
catchError(this.error.bind(this))
);
Expand All @@ -342,7 +342,7 @@ export class AuthenticationService {
return this.doGetInfo(recaptcha);
}),
catchError((err) => {
return Observable.throw(err);
return throwError(err);
}));
} else {
return this.doGetInfo();
Expand Down
3 changes: 3 additions & 0 deletions projects/grange-core/src/lib/cache.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ describe('CacheService', () => {
CACHE_REFRESH_DELAY: 1000,
}
},
{ provide: 'LANG', useValue: 'en'},
CacheService,
]
});
Expand Down Expand Up @@ -152,6 +153,7 @@ describe('CacheService', () => {
CACHE_REFRESH_DELAY: 5
}
},
{ provide: 'LANG', useValue: 'en'},
CacheService,
]
});
Expand Down Expand Up @@ -196,6 +198,7 @@ describe('CacheService', () => {
CACHE_MAX_SIZE: 2,
}
},
{ provide: 'LANG', useValue: 'en'},
CacheService,
]
});
Expand Down
8 changes: 4 additions & 4 deletions projects/grange-core/src/lib/resource.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
HttpClientTestingModule,
HttpTestingController
} from '@angular/common/http/testing';
import { fakeAsync, TestBed, tick } from '@angular/core/testing';
import { TestBed, async } from '@angular/core/testing';
import { NamedFileUpload, NavLink } from './interfaces';
import { Vocabulary } from './vocabularies';
import { APIService } from './api.service';
Expand All @@ -29,7 +29,8 @@ describe('ResourceService', () => {
useValue: {
BACKEND_URL: 'http://fake/Plone'
}
}
},
{ provide: 'LANG', useValue: 'en'},
]
});
});
Expand Down Expand Up @@ -588,7 +589,7 @@ describe('ResourceService', () => {

it(
'should get a file upload',
fakeAsync(() => {
async(() => {
const blob: { [key: string]: any } = new Blob([''], { type: 'text/csv' });
blob['name'] = 'filename.csv';

Expand All @@ -601,7 +602,6 @@ describe('ResourceService', () => {
expect(namedFile['content-type']).toBe('text/csv');
}
);
tick();
})
);
});

0 comments on commit 9993b19

Please sign in to comment.