• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

damienbod / angular-auth-oidc-client / 9308899843

30 May 2024 08:37PM CUT coverage: 92.928%. Remained the same
9308899843

Pull #1948

github

web-flow
Merge 9ccb2c964 into 33372edf1
Pull Request #1948: feat(core): adds angular 18 support

706 of 826 branches covered (85.47%)

Branch coverage included in aggregate %.

2566 of 2695 relevant lines covered (95.21%)

8.31 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.36
/projects/angular-auth-oidc-client/src/lib/storage/browser-storage.service.ts
1
import { Injectable, inject } from '@angular/core';
2
import { OpenIdConfiguration } from '../config/openid-configuration';
3
import { LoggerService } from '../logging/logger.service';
4
import { AbstractSecurityStorage } from './abstract-security-storage';
5

6
@Injectable({ providedIn: 'root' })
7
export class BrowserStorageService {
1✔
8
  private readonly loggerService = inject(LoggerService);
12✔
9

10
  private readonly abstractSecurityStorage = inject(AbstractSecurityStorage);
12✔
11

12
  read(key: string, configuration: OpenIdConfiguration): any {
13
    const { configId } = configuration;
3✔
14

15
    if (!configId) {
3!
16
      this.loggerService.logDebug(
×
17
        configuration,
18
        `Wanted to read '${key}' but configId was '${configId}'`
19
      );
20

21
      return null;
×
22
    }
23

24
    if (!this.hasStorage()) {
3✔
25
      this.loggerService.logDebug(
1✔
26
        configuration,
27
        `Wanted to read '${key}' but Storage was undefined`
28
      );
29

30
      return null;
1✔
31
    }
32

33
    const storedConfig = this.abstractSecurityStorage.read(configId);
2✔
34

35
    if (!storedConfig) {
2✔
36
      return null;
1✔
37
    }
38

39
    return JSON.parse(storedConfig);
1✔
40
  }
41

42
  write(value: any, configuration: OpenIdConfiguration): boolean {
43
    const { configId } = configuration;
3✔
44

45
    if (!configId) {
3!
46
      this.loggerService.logDebug(
×
47
        configuration,
48
        `Wanted to write but configId was '${configId}'`
49
      );
50

51
      return false;
×
52
    }
53

54
    if (!this.hasStorage()) {
3✔
55
      this.loggerService.logDebug(
1✔
56
        configuration,
57
        `Wanted to write but Storage was falsy`
58
      );
59

60
      return false;
1✔
61
    }
62

63
    value = value || null;
2✔
64

65
    this.abstractSecurityStorage.write(configId, JSON.stringify(value));
2✔
66

67
    return true;
2✔
68
  }
69

70
  remove(key: string, configuration: OpenIdConfiguration): boolean {
71
    if (!this.hasStorage()) {
2✔
72
      this.loggerService.logDebug(
1✔
73
        configuration,
74
        `Wanted to remove '${key}' but Storage was falsy`
75
      );
76

77
      return false;
1✔
78
    }
79

80
    // const storage = this.getStorage(configuration);
81
    // if (!storage) {
82
    //   this.loggerService.logDebug(configuration, `Wanted to write '${key}' but Storage was falsy`);
83

84
    //   return false;
85
    // }
86

87
    this.abstractSecurityStorage.remove(key);
1✔
88

89
    return true;
1✔
90
  }
91

92
  // TODO THIS STORAGE WANTS AN ID BUT CLEARS EVERYTHING
93
  clear(configuration: OpenIdConfiguration): boolean {
94
    if (!this.hasStorage()) {
2✔
95
      this.loggerService.logDebug(
1✔
96
        configuration,
97
        `Wanted to clear storage but Storage was falsy`
98
      );
99

100
      return false;
1✔
101
    }
102

103
    // const storage = this.getStorage(configuration);
104
    // if (!storage) {
105
    //   this.loggerService.logDebug(configuration, `Wanted to clear storage but Storage was falsy`);
106

107
    //   return false;
108
    // }
109

110
    this.abstractSecurityStorage.clear();
1✔
111

112
    return true;
1✔
113
  }
114

115
  private hasStorage(): boolean {
116
    return typeof Storage !== 'undefined';
1✔
117
  }
118
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc