Skip to content

Commit

Permalink
feat: minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pritamstyz4ever committed Sep 1, 2020
1 parent f7ce54f commit 9fdabb7
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 57 deletions.
78 changes: 37 additions & 41 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,52 +34,48 @@ const CUSTOM_PLUGINS = [
* @return {http.Server} A listener: NodeJS http.Server object
*/
module.exports = async (config) => {
try {
let corsOrigins = [config.ecosystem.ui];
let corsOrigins = [config.ecosystem.ui];

if (Array.isArray(config.ecosystem.allowCors)) {
corsOrigins = corsOrigins.concat(config.ecosystem.allowCors);
}
if (Array.isArray(config.ecosystem.allowCors)) {
corsOrigins = corsOrigins.concat(config.ecosystem.allowCors);
}

// Allow ui to query store
const cors = {
origin: corsOrigins
};
// Allow ui to query store
const cors = {
origin: corsOrigins
};

// Create a server with a host and port
// Use Object.assign to pass httpd config
const server = Hapi.server({
routes: {
cors,
log: { collect: true },
payload: { timeout: 60000 }
},
router: {
stripTrailingSlash: true
},
cache: [config.cache],
...config.httpd
});
// Create a server with a host and port
// Use Object.assign to pass httpd config
const server = Hapi.server({
routes: {
cors,
log: { collect: true },
payload: { timeout: 60000 }
},
router: {
stripTrailingSlash: true
},
cache: [config.cache],
...config.httpd
});

// Register Plugins
/* eslint-disable */
const coreRegistrations = CORE_PLUGINS.map(plugin => require(plugin));
const customRegistrations = CUSTOM_PLUGINS.map(plugin => ({
plugin: require(`../plugins/${plugin}`),
options: config[plugin] || {}
}));
/* eslint-enable */
// Register Plugins
/* eslint-disable */
const coreRegistrations = CORE_PLUGINS.map(plugin => require(plugin));
const customRegistrations = CUSTOM_PLUGINS.map(plugin => ({
plugin: require(`../plugins/${plugin}`),
options: config[plugin] || {}
}));
/* eslint-enable */

await server.register(coreRegistrations.concat(customRegistrations), {
routes: {
prefix: '/v1'
}
});
await server.register(coreRegistrations.concat(customRegistrations), {
routes: {
prefix: '/v1'
}
});

await server.start();
await server.start();

return server;
} catch (err) {
throw err;
}
return server;
};
48 changes: 32 additions & 16 deletions test/plugins/builds.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ describe('builds plugin test', () => {
credentials: {
username: mockBuildID,
scope: ['user']
} },
}
},
url: `/builds/${mockBuildID}/foo`
}).then((response) => {
assert.equal(response.statusCode, 404);
Expand Down Expand Up @@ -114,7 +115,8 @@ describe('builds plugin test', () => {
credentials: {
username: mockBuildID,
scope: ['user']
} },
}
},
url: `/builds/${mockBuildID}/foo`
}).then((response) => {
assert.equal(response.statusCode, 500);
Expand Down Expand Up @@ -142,7 +144,8 @@ describe('builds plugin test', () => {
credentials: {
username: mockBuildID,
scope: ['user']
} },
}
},
url: `/builds/${mockBuildID}/foo.html`
});

Expand Down Expand Up @@ -173,7 +176,8 @@ describe('builds plugin test', () => {
credentials: {
username: mockBuildID,
scope: ['user']
} },
}
},
url: `/builds/${mockBuildID}/foo`
});

Expand Down Expand Up @@ -202,7 +206,8 @@ describe('builds plugin test', () => {
credentials: {
username: mockBuildID,
scope: ['build']
} }
}
}
};
});

Expand Down Expand Up @@ -246,7 +251,8 @@ describe('builds plugin test', () => {
credentials: {
username: mockBuildID,
scope: ['user']
} }
}
}
});

assert.equal(getResponse.statusCode, 200);
Expand All @@ -262,7 +268,8 @@ describe('builds plugin test', () => {
credentials: {
username: mockBuildID,
scope: ['user']
} }
}
}
});

assert.equal(downloadResponse.statusCode, 200);
Expand All @@ -287,7 +294,8 @@ describe('builds plugin test', () => {
credentials: {
username: mockBuildID,
scope: ['user']
} }
}
}
});

assert.equal(getResponse.statusCode, 200);
Expand All @@ -303,7 +311,8 @@ describe('builds plugin test', () => {
credentials: {
username: mockBuildID,
scope: ['user']
} }
}
}
});

assert.equal(downloadResponse.statusCode, 200);
Expand All @@ -327,7 +336,8 @@ describe('builds plugin test', () => {
credentials: {
username: mockBuildID,
scope: ['user']
} }
}
}
}).then((getResponse) => {
assert.equal(getResponse.statusCode, 200);
assert.equal(getResponse.headers['content-type'], 'text/plain; charset=utf-8');
Expand All @@ -351,7 +361,8 @@ describe('builds plugin test', () => {
credentials: {
username: mockBuildID,
scope: ['user']
} }
}
}
}).then((getResponse) => {
assert.equal(getResponse.statusCode, 200);
assert.equal(getResponse.headers['content-type'], 'text/html; charset=utf-8');
Expand All @@ -376,7 +387,8 @@ describe('builds plugin test', () => {
credentials: {
username: mockBuildID,
scope: ['pipeline']
} }
}
}
}).then((getResponse) => {
assert.equal(getResponse.statusCode, 200);
assert.equal(getResponse.result, 'THIS IS A TEST');
Expand Down Expand Up @@ -477,7 +489,8 @@ describe('builds plugin test using s3', () => {
credentials: {
username: mockBuildID,
scope: ['user']
} },
}
},
url: `/builds/${mockBuildID}/foo.zip`
}).then((response) => {
assert.calledWith(getDownloadStreamMock, {
Expand All @@ -501,7 +514,8 @@ describe('builds plugin test using s3', () => {
credentials: {
username: mockBuildID,
scope: ['user']
} },
}
},
url: `/builds/${mockBuildID}/foo.zip`
}).then((response) => {
assert.calledWith(getDownloadStreamMock, {
Expand All @@ -528,7 +542,8 @@ describe('builds plugin test using s3', () => {
credentials: {
username: mockBuildID,
scope: ['build']
} },
}
},
url: `/builds/${mockBuildID}/foo.zip`
};
});
Expand All @@ -547,7 +562,8 @@ describe('builds plugin test using s3', () => {
strategy: 'token',
credentials: {
scope: ['user']
} }
}
}
}).then((getResponse) => {
assert.equal(getResponse.statusCode, 204);
assert.equal(getResponse.headers['content-type'], 'application/octet-stream');
Expand Down

0 comments on commit 9fdabb7

Please sign in to comment.