Update AuthIdentityTokenManager tests

Signed-off-by: Nataliya Issayeva <nissayeva@users.noreply.github.com>
This commit is contained in:
Nataliya Issayeva
2021-11-08 17:09:50 -05:00
parent 8fa1098cd5
commit fa6a9b797f
2 changed files with 19 additions and 9 deletions
+1
View File
@@ -83,6 +83,7 @@
},
"devDependencies": {
"@backstage/cli": "^0.9.0",
"@backstage/core-app-api": "^0.1.21",
"@backstage/test-utils": "^0.1.22",
"@types/archiver": "^5.1.0",
"@types/compression": "^1.7.0",
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ConfigReader } from '@backstage/core-app-api';
import { PluginEndpointDiscovery } from '..';
import { IdentityClient } from '../identity';
import { AuthIdentityTokenManager } from './AuthIdentityTokenManager';
@@ -25,6 +26,9 @@ const discovery: PluginEndpointDiscovery = {
return 'url';
},
};
const config = new ConfigReader({
backend: { auth: { secret: 'a-secret-key' } },
});
beforeAll(() => {
jest
@@ -35,23 +39,28 @@ beforeAll(() => {
});
describe('AuthIdentityTokenManager', () => {
it('should validate a valid server token', async () => {
const tokenManager = new AuthIdentityTokenManager(
discovery,
'a-secret-key',
it('should throw in getServerToken if there is no secret in the config', async () => {
const emptyConfig = new ConfigReader({});
const tokenManager = new AuthIdentityTokenManager(discovery, emptyConfig);
await expect(tokenManager.getServerToken()).rejects.toThrow(
'No server token defined in config',
);
});
it('should validate a valid server token', async () => {
const tokenManager = new AuthIdentityTokenManager(discovery, config);
const { token } = await tokenManager.getServerToken();
await expect(tokenManager.validateToken(token)).resolves.toBeUndefined();
});
it('should reject an invalid server token', async () => {
const tokenManager = new AuthIdentityTokenManager(
discovery,
'a-secret-key',
);
const differentConfig = new ConfigReader({
backend: { auth: { secret: 'a-different-key' } },
});
const tokenManager = new AuthIdentityTokenManager(discovery, config);
const differentTokenManager = new AuthIdentityTokenManager(
discovery,
'a-different-key',
differentConfig,
);
const { token } = await tokenManager.getServerToken();
await expect(differentTokenManager.validateToken(token)).rejects.toThrow(