-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e7192f3
commit 78f1e4d
Showing
11 changed files
with
626 additions
and
16 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 |
---|---|---|
|
@@ -31,4 +31,7 @@ tests/node_modules | |
tests/screenshot* | ||
|
||
# notebooks | ||
.ipynb_checkpoints | ||
.ipynb_checkpoints | ||
|
||
/.idea | ||
/log |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
/node_modules | ||
lib/dbArhives | ||
/coverage |
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,115 @@ | ||
'use strict' | ||
|
||
const nconf = require('nconf') | ||
const path = require('path') | ||
const configFilePath = path.join(__dirname, "./config/default.json") | ||
nconf.file({file: configFilePath}) | ||
|
||
const testConfig = nconf.get('test') | ||
|
||
const jest_setup = require('../jest-setup') | ||
const config = require("../lib/config"); | ||
jest.mock('axios') | ||
|
||
const DEFAULT_URL = `${testConfig.DEFAULT_URL}/` | ||
|
||
describe('Loads nconf plus base config', () => { | ||
const CONFIG_FILE_OUTPUT = { | ||
"keys": {"gofr": "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDdeFrJr76IQ+SYAoAIw8crZKNW\nir2re7Z7Iu+XzeYYop5+36Ux6uEQKSXo7s1xY2ou9nCkVAddZ1qehBo0e2MCtk62\nmQJbBT18fiZ3veQPvb0LC/9aFl64RuOguPrCZC+sbZLegQ6Wwf96UWyqmR49gaHO\nEdXwdFdSVyBGyS7dmwIDAQAB\n-----END PUBLIC KEY-----"}, | ||
"additionalConfig": {"gofr-config": "gofr-config"}, | ||
"mCSD": { | ||
"server": { | ||
"protocal": "http", | ||
"host": "localhost", | ||
"port": "8090", | ||
"basePath": "fhir", | ||
"username": "", | ||
"password": "" | ||
}, | ||
"fakeOrgId": "eac583d2-d1ba-11e8-a8d5-f2801f1b9fd1", | ||
"fakeOrgName": "Taifafeki", | ||
"cacheTime": 1200, | ||
"registryDB": "DEFAULT" | ||
}, | ||
} | ||
|
||
const CONFIG_FULL_OUTPUT = { | ||
"additionalConfig": { | ||
"gofr-config": "gofr-config" | ||
}, "keys": { | ||
"gofr": "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDdeFrJr76IQ+SYAoAIw8crZKNW\nir2re7Z7Iu+XzeYYop5+36Ux6uEQKSXo7s1xY2ou9nCkVAddZ1qehBo0e2MCtk62\nmQJbBT18fiZ3veQPvb0LC/9aFl64RuOguPrCZC+sbZLegQ6Wwf96UWyqmR49gaHO\nEdXwdFdSVyBGyS7dmwIDAQAB\n-----END PUBLIC KEY-----" | ||
}, "mCSD": { | ||
"server": { | ||
"protocal": "http", | ||
"host": "localhost", | ||
"port": "8090", | ||
"basePath": "fhir", | ||
"username": "", | ||
"password": "" | ||
}, | ||
"fakeOrgId": "eac583d2-d1ba-11e8-a8d5-f2801f1b9fd1", | ||
"fakeOrgName": "Taifafeki", | ||
"cacheTime": 1200, | ||
"registryDB": "DEFAULT" | ||
}, | ||
} | ||
|
||
const MOCK_FHIR_OBJECT = { | ||
"resourceType": "Parameters", "id": "gofr-config", "meta": { | ||
"profile": ["http://gofr.org/fhir/StructureDefinition/gofr-parameters-remote-config"] | ||
}, "parameter": [{ | ||
"name": "signature", "valueSignature": { | ||
"type": [{ | ||
"code": "1.2.840.10065.1.12.1.14", "system": "urn:iso-astm:E1762-95:2013" | ||
}], | ||
"when": "2022-09-20T03:44:20.575Z", | ||
"who": { | ||
"reference": "http://gofr.org/fhir/Organization/gofr" | ||
}, | ||
"data": "Td3sLJzy//AlrMy/w+FMYkv1V2zd7vro0+sQiQK32CwXun1B9MYMTLLA214BWsOmnUhi82Dojo3Jn3U2GpPf0BCu47wlln1weYsLA169HDLkG50ch89p3YZ87TyNiNidctCaAHAQ4gz8W+X20szMZeqTkOy/EoEGW0+GuPNGbpw=" | ||
} | ||
}, { | ||
"name": "config", "part": [{ | ||
"name": "site:title", "valueString": "Manage" | ||
}, { | ||
"name": "site:site", "valueString": "Demo" | ||
}, { | ||
"name": "site:logo", "valueString": "iHRIS5Logo.png" | ||
}] | ||
}] | ||
} | ||
|
||
beforeEach(() => { | ||
require('axios').__setFhirResults(DEFAULT_URL + "Parameters/gofr-config", null, MOCK_FHIR_OBJECT) | ||
}) | ||
|
||
test('Check if object contains required properties', () => { | ||
let additionalConfig = config.get('additionalConfig') | ||
let keys = config.get('keys') | ||
let appConfig = config.get('app') | ||
expect(additionalConfig).toHaveProperty('gofr-config') | ||
expect(keys).toHaveProperty('gofr') | ||
expect(appConfig).toHaveProperty('site'); | ||
expect(appConfig.site).toHaveProperty('path'); | ||
expect(appConfig).toHaveProperty('core'); | ||
expect(appConfig.core).toHaveProperty('path'); | ||
}) | ||
|
||
test('loads default config from mock file and mock fhir server', () => { | ||
const nconf = require('../lib/config') | ||
let config = { | ||
additionalConfig: nconf.get('additionalConfig'), keys: nconf.get('keys'), mCSD: nconf.get('mCSD') | ||
} | ||
expect(config).toEqual(CONFIG_FILE_OUTPUT) | ||
}) | ||
|
||
test('loads default config and remote config from mock fhir server', () => { | ||
const nconf = require('../lib/config') | ||
return nconf.loadRemote().then(() => { | ||
let config = { | ||
additionalConfig: nconf.get('additionalConfig'), keys: nconf.get('keys'), mCSD: nconf.get('mCSD') | ||
} | ||
expect(config).toEqual(CONFIG_FULL_OUTPUT) | ||
}) | ||
}) | ||
}) |
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 was deleted.
Oops, something went wrong.
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,119 @@ | ||
'use strict' | ||
const nconf = require('nconf') | ||
const path = require('path') | ||
const configFilePath = path.join(__dirname, "./config/default.json") | ||
nconf.file({file: configFilePath}) | ||
|
||
const testConfig = nconf.get('test') | ||
|
||
const jest_setup = require('../jest-setup') | ||
jest.mock('axios') | ||
|
||
const DEFAULT_URL = testConfig.DEFAULT_URL | ||
|
||
const request = require("supertest") | ||
const route = require("../lib/routes/auth") | ||
|
||
const express = require('express') | ||
const app = express() | ||
app.use(express.urlencoded({extended: false})) | ||
app.use("/", route) | ||
|
||
describe('Test Auth routes', () => { | ||
describe('Test Public User', () => { | ||
test('Test Public User setup', () => { | ||
const MOCK_PUBLIC_USER = { | ||
"resourceType": "Person", "id": "26e19ebd-65e5-4181-84b6-589bcf3bc44b", "meta": { | ||
"versionId": "1", "profile": ["http://gofr.org/fhir/StructureDefinition/gofr-person-user"] | ||
}, "extension": [{ | ||
"url": "http://gofr.org/fhir/StructureDefinition/gofr-owning-organization", "valueReference": { | ||
"reference": "Organization/54cdcbe3-87e0-421f-b657-8313fce5f418" | ||
} | ||
}, { | ||
"url": "http://gofr.org/fhir/StructureDefinition/gofr-password", "extension": [{ | ||
"url": "hash", | ||
"valueString": "6906687939864f1462d52839f52c8800b9ead0aa67d050649a9eed1d9c9ffbe5d815b4d286ee2c2786d1f9781ba72df087b9a2057e8a96c4fc30e870a5cc587b" | ||
}, { | ||
"url": "salt", "valueString": "be664906fbbe50918d8cadb5ebd22093" | ||
}] | ||
}, { | ||
"url": "http://gofr.org/fhir/StructureDefinition/gofr-assign-role", "valueReference": { | ||
"reference": "Basic/gofr-role-public" | ||
} | ||
}], "name": [{ | ||
"text": "GOFR Public User" | ||
}], "telecom": [{ | ||
"system": "email", "value": "[email protected]" | ||
}, { | ||
"system": "phone" | ||
}], "active": true | ||
} | ||
require('axios').__setFhirResults(DEFAULT_URL + "/Person/26e19ebd-65e5-4181-84b6-589bcf3bc44b", null, MOCK_PUBLIC_USER) | ||
return request(app).get(`/`).then((response) => { | ||
expect(response.statusCode).toBe(200) | ||
expect(response.body).toEqual({ok: true}) | ||
}) | ||
}) | ||
}) | ||
|
||
describe('Test Local User', () => { | ||
const MOCK_LOCAL_USER_LOOKUP = { | ||
"resourceType": "Bundle", "type": "searchset", "total": 1, "entry": [{ | ||
"furllUrl": DEFAULT_URL + "Person/e9b41c35-7c85-46df-aeea-a4e8dbf0364e", "resource": { | ||
"resourceType": "Person", "id": "e9b41c35-7c85-46df-aeea-a4e8dbf0364e", "meta": { | ||
"versionId": "1", | ||
"lastUpdated": "2023-11-08T10:59:50.435+00:00", | ||
"source": "#fYi1xDSww6QUe05Y", | ||
"profile": ["http://gofr.org/fhir/StructureDefinition/gofr-person-user"] | ||
}, "extension": [{ | ||
"url": "http://gofr.org/fhir/StructureDefinition/gofr-owning-organization", "valueReference": { | ||
"reference": "Organization/54cdcbe3-87e0-421f-b657-8313fce5f418" | ||
} | ||
}, { | ||
"url": "http://gofr.org/fhir/StructureDefinition/gofr-password", "extension": [{ | ||
"url": "hash", | ||
"valueString": "727c00bcb3d604db9b807155240b97347951e5e89e4c69b823279287694501fcaa683d883f5854a05c2c50c5b31413c6bb4a5949876a42b5c5bd74247e5777fc" | ||
}, { | ||
"url": "salt", "valueString": "be664906fbbe50918d8cadb5ebd22093" | ||
}] | ||
}, { | ||
"url": "http://gofr.org/fhir/StructureDefinition/gofr-assign-role", "valueReference": { | ||
"reference": "Basic/gofr-role-admin" | ||
} | ||
}], "name": [{ | ||
"text": "GOFR Admin" | ||
}], "telecom": [{ | ||
"system": "email", "value": "[email protected]" | ||
}, { | ||
"system": "phone" | ||
}], "active": true | ||
} | ||
}] | ||
} | ||
|
||
require('axios').__setFhirResults(DEFAULT_URL + "/Person", {telecom: "email|[email protected]"}, MOCK_LOCAL_USER_LOOKUP) | ||
test('test local user login', () => { | ||
return request(app).post("/login").send("[email protected]&password=gofr").then((response) => { | ||
expect(response.statusCode).toBe(200) | ||
expect(response.body.userObj.resource).toEqual(MOCK_LOCAL_USER_LOOKUP.entry[0].resource) | ||
}) | ||
}) | ||
|
||
test('test invalid password', () => { | ||
return request(app).post("/login").send("[email protected]&password=wrong").then((response) => { | ||
expect(response.statusCode).toBe(401) | ||
}) | ||
}) | ||
|
||
test('test invalid user', () => { | ||
const MOCK_LOCAL_MISSING = { | ||
"resourceType": "Bundle", "type": "searchset", "total": 0, "entry": [] | ||
} | ||
require('axios').__setFhirResults(DEFAULT_URL + "/Person", {telecom: "email|[email protected]"}, MOCK_LOCAL_MISSING) | ||
return request(app).post("/login").send("[email protected]&password=wrong").then((response) => { | ||
expect(response.statusCode).toBe(401) | ||
}) | ||
|
||
}) | ||
}) | ||
}) |
Oops, something went wrong.