From 9993b19ef1e3e4ffc61459745fe3ea080f95fc47 Mon Sep 17 00:00:00 2001 From: Eric BREHAULT Date: Thu, 20 Feb 2020 21:09:51 +0100 Subject: [PATCH] version + cleanup --- CHANGELOG.md | 4 ++ projects/grange-core/package.json | 4 +- .../grange-core/src/lib/api.service.spec.ts | 3 +- .../src/lib/authentication.service.spec.ts | 11 ++++-- .../src/lib/authentication.service.ts | 38 +++++++++---------- .../grange-core/src/lib/cache.service.spec.ts | 3 ++ .../src/lib/resource.service.spec.ts | 8 ++-- 7 files changed, 41 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d30d60a..6659705 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/projects/grange-core/package.json b/projects/grange-core/package.json index fd18031..9e05e7c 100644 --- a/projects/grange-core/package.json +++ b/projects/grange-core/package.json @@ -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", diff --git a/projects/grange-core/src/lib/api.service.spec.ts b/projects/grange-core/src/lib/api.service.spec.ts index 41a020c..1fa3732 100644 --- a/projects/grange-core/src/lib/api.service.spec.ts +++ b/projects/grange-core/src/lib/api.service.spec.ts @@ -29,7 +29,8 @@ describe('APIService', () => { { provide: 'CONFIGURATION', useValue: { BACKEND_URL: 'http://fake/Plone', - }} + }}, + { provide: 'LANG', useValue: 'en'}, ] }); diff --git a/projects/grange-core/src/lib/authentication.service.spec.ts b/projects/grange-core/src/lib/authentication.service.spec.ts index ba2e3b8..82d2e9a 100644 --- a/projects/grange-core/src/lib/authentication.service.spec.ts +++ b/projects/grange-core/src/lib/authentication.service.spec.ts @@ -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(() => { @@ -12,11 +14,13 @@ describe('AuthenticationService', () => { providers: [ AuthenticationService, ConfigurationService, + ReCaptchaV3Service, { provide: 'CONFIGURATION', useValue: { BACKEND_URL: 'http://fake/Plone', } }, + { provide: 'LANG', useValue: 'en'}, ] }); }); @@ -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); }); diff --git a/projects/grange-core/src/lib/authentication.service.ts b/projects/grange-core/src/lib/authentication.service.ts index 2cf9d05..88c488b 100644 --- a/projects/grange-core/src/lib/authentication.service.ts +++ b/projects/grange-core/src/lib/authentication.service.ts @@ -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'; @@ -116,7 +116,7 @@ export class AuthenticationService { protected error(errorResponse: HttpErrorResponse): Observable { const error: Error = getError(errorResponse); - return Observable.throw(error); + return throwError(error); } // LOGIN LOGIC @@ -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); @@ -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'); @@ -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( @@ -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)) ); @@ -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); @@ -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)) ); @@ -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)) ); @@ -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); @@ -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)) ); @@ -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); @@ -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)) ); @@ -342,7 +342,7 @@ export class AuthenticationService { return this.doGetInfo(recaptcha); }), catchError((err) => { - return Observable.throw(err); + return throwError(err); })); } else { return this.doGetInfo(); diff --git a/projects/grange-core/src/lib/cache.service.spec.ts b/projects/grange-core/src/lib/cache.service.spec.ts index 9efd952..e752cf9 100644 --- a/projects/grange-core/src/lib/cache.service.spec.ts +++ b/projects/grange-core/src/lib/cache.service.spec.ts @@ -61,6 +61,7 @@ describe('CacheService', () => { CACHE_REFRESH_DELAY: 1000, } }, + { provide: 'LANG', useValue: 'en'}, CacheService, ] }); @@ -152,6 +153,7 @@ describe('CacheService', () => { CACHE_REFRESH_DELAY: 5 } }, + { provide: 'LANG', useValue: 'en'}, CacheService, ] }); @@ -196,6 +198,7 @@ describe('CacheService', () => { CACHE_MAX_SIZE: 2, } }, + { provide: 'LANG', useValue: 'en'}, CacheService, ] }); diff --git a/projects/grange-core/src/lib/resource.service.spec.ts b/projects/grange-core/src/lib/resource.service.spec.ts index 32d184b..1cbce8c 100644 --- a/projects/grange-core/src/lib/resource.service.spec.ts +++ b/projects/grange-core/src/lib/resource.service.spec.ts @@ -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'; @@ -29,7 +29,8 @@ describe('ResourceService', () => { useValue: { BACKEND_URL: 'http://fake/Plone' } - } + }, + { provide: 'LANG', useValue: 'en'}, ] }); }); @@ -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'; @@ -601,7 +602,6 @@ describe('ResourceService', () => { expect(namedFile['content-type']).toBe('text/csv'); } ); - tick(); }) ); });