Skip to content

Commit

Permalink
fix: more graceful handling of invalid account numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
stdavis committed May 15, 2024
1 parent e17548a commit c36c257
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
13 changes: 13 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ let app = express();

app.use(cors());

// verify account number for all paths requests except "/"
app.use((request, response, next) => {
if (request.path !== '/') {
const accountNumber = request.path.split('/')[1];
if (!accounts[accountNumber]) {
response.status(400);
return response.send(`Invalid account number: ${accountNumber}`);
}
}

return next();
});

const gotClient = got.extend({
timeout: {
request: config.TIMEOUT * SECONDS_TO_MILLISECONDS,
Expand Down
7 changes: 7 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ test('main server info', () => {
.expect(/services/);
});

test('bad account number', () => {
return request(server)
.get('/-99/arcgis/rest/info?f=json')
.expect(400)
.expect(/invalid account number/i);
});

test('export task info', () => {
return request(server)
.get('/-1/arcgis/rest/services/GPServer/export?f=json')
Expand Down

0 comments on commit c36c257

Please sign in to comment.