-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
121 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import mockAxios from 'axios'; | ||
import LDAPJWTAuthProvider from './ldapJWTAuthProvider'; | ||
|
||
describe('LDAP-JWT Auth provider', () => { | ||
let ldapJWTAuthProvider: LDAPJWTAuthProvider; | ||
|
||
beforeEach(() => { | ||
ldapJWTAuthProvider = new LDAPJWTAuthProvider('http://localhost:8000'); | ||
}); | ||
|
||
it('should call api to fetch maintenance state', async () => { | ||
vi.mocked(mockAxios.get).mockImplementation(() => | ||
Promise.resolve({ | ||
data: { | ||
show: false, | ||
message: 'test', | ||
}, | ||
}) | ||
); | ||
|
||
await ldapJWTAuthProvider.fetchMaintenanceState(); | ||
expect(mockAxios.get).toHaveBeenCalledWith( | ||
'http://localhost:8000/maintenance' | ||
); | ||
}); | ||
|
||
it('should call api to fetch scheduled maintenance state', async () => { | ||
vi.mocked(mockAxios.get).mockImplementation(() => | ||
Promise.resolve({ | ||
data: { | ||
show: false, | ||
message: 'test', | ||
severity: 'error', | ||
}, | ||
}) | ||
); | ||
|
||
await ldapJWTAuthProvider.fetchScheduledMaintenanceState(); | ||
expect(mockAxios.get).toHaveBeenCalledWith( | ||
'http://localhost:8000/scheduled_maintenance' | ||
); | ||
}); | ||
|
||
it('should log the user out if it fails to fetch maintenance state', async () => { | ||
vi.mocked(mockAxios.get).mockImplementation(() => | ||
Promise.reject({ | ||
response: { | ||
status: 401, | ||
}, | ||
}) | ||
); | ||
|
||
await ldapJWTAuthProvider.fetchMaintenanceState().catch(() => { | ||
// catch error | ||
}); | ||
|
||
expect(ldapJWTAuthProvider.isLoggedIn()).toBeFalsy(); | ||
}); | ||
|
||
it('should log the user out if it fails to fetch scheduled maintenance state', async () => { | ||
vi.mocked(mockAxios.get).mockImplementation(() => | ||
Promise.reject({ | ||
response: { | ||
status: 401, | ||
}, | ||
}) | ||
); | ||
|
||
await ldapJWTAuthProvider.fetchScheduledMaintenanceState().catch(() => { | ||
// catch error | ||
}); | ||
|
||
expect(ldapJWTAuthProvider.isLoggedIn()).toBeFalsy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import Axios from 'axios'; | ||
import JWTAuthProvider from './jwtAuthProvider'; | ||
import { ScheduledMaintenanceState } from '../state/scigateway.types'; | ||
import { MaintenanceState } from '../state/scigateway.types'; | ||
|
||
export default class LDAPJWTAuthProvider extends JWTAuthProvider { | ||
public fetchScheduledMaintenanceState(): Promise<ScheduledMaintenanceState> { | ||
return Axios.get(`${this.authUrl}/scheduled_maintenance`) | ||
.then((res) => { | ||
return res.data; | ||
}) | ||
.catch((err) => { | ||
this.handleAuthError(err); | ||
}); | ||
} | ||
|
||
public fetchMaintenanceState(): Promise<MaintenanceState> { | ||
return Axios.get(`${this.authUrl}/maintenance`) | ||
.then((res) => { | ||
return res.data; | ||
}) | ||
.catch((err) => { | ||
this.handleAuthError(err); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters