Skip to content
This repository has been archived by the owner on May 8, 2020. It is now read-only.

Commit

Permalink
fix(server): Update server implementations to be more docker-friendly
Browse files Browse the repository at this point in the history
  • Loading branch information
zakhenry committed Aug 1, 2016
1 parent fafc747 commit cae672a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/server/servers/abstract.server.spec.ts
Expand Up @@ -63,7 +63,7 @@ describe('Server', () => {
.toHaveBeenCalledWith(3001);

expect(server.getHost())
.toEqual('http://localhost:3000');
.toEqual('http://(localhost):3000');

}));

Expand Down
7 changes: 3 additions & 4 deletions src/server/servers/abstract.server.ts
Expand Up @@ -47,9 +47,8 @@ export abstract class Server {

this.logger = loggerBase.source('server');

//@todo pull this config from process.env via .env variables
this.host = 'localhost';
this.port = 3000;
this.host = process.env.APP_HOST || null; //usually should be null to default binding to localhost
this.port = process.env.APP_PORT || 3000;

this.initialize();

Expand Down Expand Up @@ -101,7 +100,7 @@ export abstract class Server {
* @returns {string}
*/
public getHost(): string {
return `http://${this.host}:${this.port}`;
return `http://${this.host || '(localhost)'}:${this.port}`;
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/server/services/jwtAuthStrategy.spec.ts
Expand Up @@ -15,6 +15,8 @@ describe('JWT Authentication Strategy', () => {
};
authService.verify.and.returnValue(Promise.resolve(payload));

process.env.PATH_ROOT = '/tmp'; //tmp for testing

const context: RemoteCliContext = {
logger: loggerMock,
authService: authService,
Expand Down Expand Up @@ -49,10 +51,10 @@ describe('JWT Authentication Strategy', () => {

authenticator({client: {jwt, publicKeyPath, columns: 100}}, (message:string, isSuccess:boolean) => {

expect(authService.verify).toHaveBeenCalledWith(jwt, publicKeyPath);
expect(authService.verify).toHaveBeenCalledWith(jwt, '/tmp/path/to/key');

expect(vantageScope.log)
.toHaveBeenCalledWith(chalk.grey(`You were authenticated with a JSON Web token verified against the public key at ${publicKeyPath}`));
.toHaveBeenCalledWith(chalk.grey(`You were authenticated with a JSON Web token verified against the public key at /tmp/path/to/key`));

expect(isSuccess).toBe(true);
expect(message).toBe(null);
Expand Down
7 changes: 6 additions & 1 deletion src/server/services/jwtAuthStrategy.ts
Expand Up @@ -4,6 +4,7 @@
/** End Typedoc Module Declaration */
import { bannerBg } from '../../common/util/banner';
import * as chalk from 'chalk';
import * as path from 'path';
import {
AuthenticationStrategy,
RemoteCliContext,
Expand All @@ -19,12 +20,16 @@ export const jwtAuthStrategyFactory:AuthenticationStrategyFactory = (remoteCliCo
remoteCliContext.logger.silly.debug('Passed client arguments: ', args);

const token: string = args.client.jwt;
const keyPath: string = args.client.publicKeyPath;
let keyPath: string = args.client.publicKeyPath;

if (!token) {
return cb("JWT was not passed in connection request", false);
}

if (process.env.PATH_ROOT){
keyPath = path.resolve(process.env.PATH_ROOT, keyPath);
}

remoteCliContext.logger.info(`Authenticating JSON web token against public key [${keyPath}]`);

remoteCliContext.authService.verify(token, keyPath)
Expand Down

0 comments on commit cae672a

Please sign in to comment.