Permalink
Browse files

fix(logs): do not allow logger to emit prematurely (closes #164)

  • Loading branch information...
jkuri committed Sep 17, 2017
1 parent d2e58a1 commit 31796ba93855c67e3ffa03e854f32504d284e8c3
Showing with 54 additions and 149 deletions.
  1. +8 −8 e2e/050_builds.e2e.ts
  2. +1 −84 e2e/060_build.e2e.ts
  3. +3 −3 e2e/080_bitbucket.e2e.ts
  4. +3 −3 e2e/090_gitlab.e2e.ts
  5. +3 −3 e2e/100_gogs.e2e.ts
  6. +2 −2 e2e/110_team.e2e.ts
  7. +1 −1 protractor.conf.js
  8. +12 −9 src/api/index.ts
  9. +21 −36 src/api/security.ts
@@ -89,7 +89,7 @@ describe('Builds', () => {
});

it('should start new build (send push event)', () => {
return sendGitHubRequest(pushEventRequest, pushEventHeader)
return sendGitHubRequest(requestD3, pushEventHeader)
.then((): any => browser.wait(() => element.all(by.css('.list-item')).count().then(cnt => {
return cnt === 3;
})))
@@ -103,11 +103,11 @@ describe('Builds', () => {
return element.all(by.css('.disabled')).count().then(cnt => cnt === 0);
}))
.then((): any => browser.wait(() => {
return element.all(by.css('.stop-build')).first().isPresent();
return element.all(by.css('.list-item:nth-child(1) .stop-build')).isPresent();
}))
.then((): any => {
return browser.wait(() => {
const el = element(by.css('.stop-build'));
const el = element(by.css('.list-item:nth-child(1) .stop-build'));
return ExpectedConditions.elementToBeClickable(el);
});
})
@@ -120,9 +120,9 @@ describe('Builds', () => {

it('should restart last build and send same push event, the old build should stop', () => {
return Promise.resolve()
.then((): any => browser.wait(() => {
return element.all(by.css('.is-running')).count().then(count => count === 0);
}))
.then((): any => browser.wait(() => {
return element.all(by.css('.is-running')).count().then(count => count === 0);
}))
.then((): any => browser.wait(() => {
return element.all(by.css('.restart-build')).first().isPresent();
}))
@@ -131,7 +131,7 @@ describe('Builds', () => {
.then((): any => browser.wait(() => {
return element.all(by.css('.is-running')).count().then(count => count === 1);
}))
.then(() => sendGitHubRequest(pushEventRequest, pushEventHeader))
.then(() => sendGitHubRequest(requestD3, pushEventHeader))
.then((): any => browser.wait(() => {
return element.all(by.css('.is-running')).count().then(count => count === 1);
}))
@@ -151,7 +151,7 @@ describe('Builds', () => {
}));
});

it('should restart last build', () => {
xit('should restart last build', () => {
return Promise.resolve()
.then((): any => browser.wait(() => {
return element.all(by.css('.disabled')).count().then(cnt => cnt === 0);
@@ -149,7 +149,7 @@ describe('Build Details', () => {
});
});

xit('should start new build (D3) and see progress bar in second job run', () => {
it('should start new build (D3) and see progress bar in second job run', () => {
return Promise.resolve()
.then(() => browser.get('/'))
.then(() => sendGitHubRequest(requestD3, header))
@@ -245,87 +245,4 @@ describe('Build Details', () => {
.then(() => delay(1000))
.then((): any => element(by.css(`[name="stop-build"]`)).click());
});

// it('should test button load more', () => {
// return Promise.resolve()
// .then(() => browser.get('/'))
// .then((): any => browser.wait(() => element.all(by.css('.list-item')).count().then(cnt => {
// return cnt === 5;
// })))
// .then(() => sendGitHubRequest(requestD3, header))
// .then((): any => browser.wait(() => element.all(by.css('.list-item')).count().then(cnt => {
// return cnt === 5;
// })))
// .then((): any => browser.wait(() => {
// return element.all(by.css('.is-running')).count().then(count => count === 1);
// }))
// .then((): any => browser.wait(() => {
// return element.all(by.css('.list-item:nth-child(1) .stop-build')).first().isPresent();
// }))
// .then((): any => {
// return browser.wait(() => {
// const el = element(by.css('.list-item:nth-child(1) .stop-build'));
// return ExpectedConditions.elementToBeClickable(el);
// });
// })
// .then((): any => element.all(by.css('.stop-build')).first().click())
// .then((): any => browser.wait(() => {
// return element.all(by.css('.is-running')).count().then(count => count === 0);
// }))
// .then((): any => browser.wait(() => element.all(by.css('.list-item')).count().then(cnt => {
// return cnt === 5;
// })))
// .then((): any => element.all(by.css('.list-item')).last().click())
// .then((): any => waitForUrlToChangeTo('http://localhost:6500/build/2'))
// .then(() => browser.get('/'))
// .then((): any => browser.wait(() => element(by.css('[name="btn-loadmore"]')).isPresent()))
// .then((): any => element(by.css('[name="btn-loadmore"]')).click())
// .then((): any => browser.wait(() => element.all(by.css('.list-item')).count().then(cnt => {
// return cnt === 6;
// })))
// .then((): any => element.all(by.css('.list-item')).last().click())
// .then((): any => waitForUrlToChangeTo('http://localhost:6500/build/1'))
// .then(() => browser.get('/'))
// .then((): any => browser.wait(() => element.all(by.css('.list-item')).count().then(cnt => {
// return cnt === 5;
// })));
// });

// it('should restart all jobs', () => {
// return Promise.resolve()
// .then((): any => browser.wait(() => element.all(by.css('.list-item')).count().then(cnt => {
// return cnt > 0;
// })))
// .then((): any => browser.wait(() => element.all(by.css('.is-running')).count().then(cnt => {
// return cnt === 0;
// })))
// .then((): any => {
// return browser.wait(() => {
// return element.all(by.css(`[name="restart-job"]`)).each(el => el.isPresent());
// });
// })
// .then((): any => element.all(by.css(`[name="restart-job"]`)).each(el => el.click()))
// .then((): any => element.all(by.css('.list-item')).count())
// .then((num): any => {
// return browser.wait(() => element.all(by.css('.is-running')).count()
// .then(cnt => cnt === num));
// })
// .then((): any => {
// return browser.wait(() => element.all(by.css('.job-time')).each(el => {
// return el.getAttribute('innerHTML').then(html => parseInt(html, 10) > 5);
// }));
// })
// .then((): any => {
// return browser.wait(() => {
// return element.all(by.css(`[name="stop-job"]`)).each(el => el.isPresent());
// });
// })
// .then((): any => {
// return element.all(by.css(`[name="stop-job"]`)).each(el => el.click());
// })
// .then((num): any => {
// return browser.wait(() => element.all(by.css('.is-running')).count()
// .then(cnt => cnt === 0));
// });
// });
});
@@ -19,7 +19,7 @@ describe('Bitbucket repositories', () => {
logout().then(() => browser.waitForAngularEnabled(true));
});

xit('should add bitbucket repository and start new build (send push event)', () => {
it('should add bitbucket repository and start new build (send push event)', () => {
return browser.wait(() => {
return element.all(by.css('.is-running')).count().then(count => count === 0);
})
@@ -42,7 +42,7 @@ describe('Bitbucket repositories', () => {
}));
});

xit('should start new build (send reopen_pull_request event)', () => {
it('should start new build (send reopen_pull_request event)', () => {
return sendBitBucketRequest(prReq, headerPullRequestCreated)
.then((): any => browser.wait(() => {
return element.all(by.css('.is-running')).count().then(count => count === 1);
@@ -69,7 +69,7 @@ describe('Bitbucket repositories', () => {
}));
});

xit('should restart last build', () => {
it('should restart last build', () => {
return Promise.resolve()
.then((): any => browser.wait(() => {
return element.all(by.css('.disabled')).count().then(cnt => cnt === 0);
@@ -9,7 +9,7 @@ describe('Gitlab repositories', () => {
beforeAll(() => login().then(() => browser.waitForAngularEnabled(false)));
afterAll(() => logout().then(() => browser.waitForAngularEnabled(true)));

xit('should add gitlab repository and start new build (send push event)', () => {
it('should add gitlab repository and start new build (send push event)', () => {
return browser.wait(() => {
return element.all(by.css('.is-running')).count().then(count => count === 0);
})
@@ -32,7 +32,7 @@ describe('Gitlab repositories', () => {
}));
});

xit('should start new build (send reopen_pull_request event)', () => {
it('should start new build (send reopen_pull_request event)', () => {
return sendGitLabRequest(prReq, prHead)
.then((): any => browser.wait(() => {
return element.all(by.css('.is-running')).count().then(count => count === 1);
@@ -59,7 +59,7 @@ describe('Gitlab repositories', () => {
}));
});

xit('should restart last build', () => {
it('should restart last build', () => {
return Promise.resolve()
.then((): any => browser.wait(() => {
return element.all(by.css('.disabled')).count().then(cnt => cnt === 0);
@@ -9,7 +9,7 @@ describe('Gogs repositories', () => {
beforeAll(() => login().then(() => browser.waitForAngularEnabled(false)));
afterAll(() => logout().then(() => browser.waitForAngularEnabled(true)));

xit('should add gogs repository and start new build (send push event)', () => {
it('should add gogs repository and start new build (send push event)', () => {
return browser.wait(() => {
return element.all(by.css('.is-running')).count().then(count => count === 0);
})
@@ -32,7 +32,7 @@ describe('Gogs repositories', () => {
}));
});

xit('should start new build (send reopen_pull_request event)', () => {
it('should start new build (send reopen_pull_request event)', () => {
return sendGogsRequest(pullRequestOpened, prHead)
.then((): any => browser.wait(() => {
return element.all(by.css('.is-running')).count().then(count => count === 1);
@@ -53,7 +53,7 @@ describe('Gogs repositories', () => {
}));
});

xit('should restart last build', () => {
it('should restart last build', () => {
return Promise.resolve()
.then((): any => browser.wait(() => {
return element.all(by.css('.disabled')).count().then(cnt => cnt === 0);
@@ -29,7 +29,7 @@ describe('Teams', () => {
}));
});

xit('should redirect to team, user and then grant, revoke repository permission', () => {
it('should redirect to team, user and then grant, revoke repository permission', () => {
return browser.get('/')
.then((): any => browser.wait(() => element(by.css('.nav-team')).isPresent()))
.then((): any => element(by.css('.nav-team')).click())
@@ -61,7 +61,7 @@ describe('Teams', () => {
}));
});

xit(`should logout, access page as annonymous, see public build, job, but can't restart it`,
it(`should logout, access page as annonymous, see public build, job, but can't restart it`,
() => {
return browser.get('/')
.then(() => isLoaded())
@@ -8,7 +8,7 @@ exports.config = {
capabilities: {
browserName: 'chrome',
chromeOptions: {
// args: ['--headless', '--disable-gpu', '--window-size=1024,768']
args: ['--headless', '--disable-gpu', '--window-size=1024,768']
}
},
directConnect: true,
@@ -20,18 +20,21 @@ import * as db from './db/migrations';
const server = new ExpressServer({ port: 6500 });
const socket = new SocketServer({ port: 6501 });

const msg: LogMessageType = {
message: '[server] starting Abstruse CI server...',
type: 'info',
notify: false
};
logger.next(msg);

initSetup()
.then(() => Promise.all([generatePublicKey(), generatePrivateKey()]))
.then(() => db.create())
.then(() => {
Observable.merge(...[server.start(), socket.start()])
const msg: LogMessageType = {
message: '[server] starting Abstruse CI server...',
type: 'info',
notify: false
};
logger.next(msg);
})
.then(() => {
Observable
.merge(...[server.start(), socket.start()])
.concat(generatePublicKey())
.concat(generatePrivateKey())
.subscribe(data => {
const msg: LogMessageType = { message: data, type: 'info', notify: false };
logger.next(msg);
@@ -7,6 +7,7 @@ import { getFilePath, getConfig } from './utils';
import { existsSync, exists, writeFile } from './fs';
import { readFileSync } from 'fs';
import { logger, LogMessageType } from './logger';
import { Observable } from 'rxjs';

export function generatePassword(plain: string): Promise<string> {
return new Promise((resolve, reject) => {
@@ -73,70 +74,54 @@ export function decrypt(str: string, config: any): string {
}
}

export function generatePublicKey(): Promise<void> {
return new Promise((resolve, reject) => {
export function generatePublicKey(): Observable<string> {
return new Observable(observer => {
const config: any = getConfig();
const publicKeyPath = getFilePath(config.publicKey);

if (existsSync(publicKeyPath)) {
return resolve();
observer.complete();
} else {
const msg: LogMessageType = {
message: '[encrypt]: generating RSA public key...',
type: 'info',
notify: false
};
logger.next(msg);
observer.next(`[encrypt]: generating RSA public key...`);

const key = new nodeRsa({b: 4096});
const publicKey = key.exportKey('public').toString();

writeFile(publicKeyPath, publicKey)
.then(() => {
const msg: LogMessageType = {
message: '[encrypt]: RSA public key successfully generated',
type: 'info',
notify: false
};
logger.next(msg);

resolve();
observer.next('[encrypt]: RSA public key successfully generated');
observer.complete();
})
.catch(err => reject(err));
.catch(err => {
observer.error(err);
observer.complete();
});
}
});
}

export function generatePrivateKey(): Promise<void> {
return new Promise((resolve, reject) => {
export function generatePrivateKey(): Observable<string> {
return new Observable(observer => {
const config: any = getConfig();
const privateKeyPath = getFilePath(config.privateKey);

if (existsSync(privateKeyPath)) {
return resolve();
observer.complete();
} else {
const msg: LogMessageType = {
message: '[encrypt]: generating RSA private key...',
type: 'info',
notify: false
};
logger.next(msg);
observer.next('[encrypt]: generating RSA private key...');

const key = new nodeRsa({b: 4096});
const privateKey = key.exportKey('private').toString();

writeFile(privateKeyPath, privateKey)
.then(() => {
const msg: LogMessageType = {
message: '[encrypt]: RSA private key successfully generated',
type: 'info',
notify: false
};
logger.next(msg);

resolve();
observer.next('[encrypt]: RSA private key successfully generated');
observer.complete();
})
.catch(err => reject(err));
.catch(err => {
observer.error(err);
observer.complete();
});
}
});
}

0 comments on commit 31796ba

Please sign in to comment.