Skip to content

Commit 11fb2d4

Browse files
shiradyjackyalbo
authored andcommitted
Handle the case where the endpoint port was wrong
1. Handle the case where the endpoint port was wrong - for example: - S3 port with IAM action - IAM port with S3 action Signed-off-by: shirady <[email protected]> (cherry picked from commit 5d071d4)
1 parent b22ebac commit 11fb2d4

File tree

3 files changed

+18
-21
lines changed

3 files changed

+18
-21
lines changed

src/endpoint/iam/iam_rest.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ async function handle_request(req, res) {
9898
await http_utils.read_and_parse_body(req, options);
9999

100100
const op_name = parse_op_name(req, req.body.action);
101+
const op = IAM_OPS[op_name];
102+
if (!op || !op.handler) {
103+
dbg.error('IAM (NotImplemented)', op_name, req.method, req.originalUrl);
104+
throw new IamError(IamError.NotImplemented);
105+
}
101106
req.op_name = op_name;
102107

103108
http_utils.authorize_session_token(req, headers_options);
@@ -106,12 +111,6 @@ async function handle_request(req, res) {
106111

107112
dbg.log1('IAM REQUEST', req.method, req.originalUrl, 'op', op_name, 'request_id', req.request_id, req.headers);
108113

109-
const op = IAM_OPS[op_name];
110-
if (!op || !op.handler) {
111-
dbg.error('IAM TODO (NotImplemented)', op_name, req.method, req.originalUrl);
112-
throw new IamError(IamError.NotImplemented);
113-
}
114-
115114
const reply = await op.handler(req, res);
116115
add_response_metadata_if_not_exists(reply, req.request_id); // unique to IAM
117116
http_utils.send_reply(req, res, reply, {
@@ -171,9 +170,9 @@ function handle_error(req, res, err) {
171170
// we only support request with specific type
172171
function verify_op_request_body_type(req) {
173172
const headers = req.headers['content-type'];
174-
if (!headers.includes(http_utils.CONTENT_TYPE_APP_FORM_URLENCODED)) {
175-
dbg.error(`verify_op_request_body_type: should have header ${http_utils.CONTENT_TYPE_APP_FORM_URLENCODED}` +
176-
`in request, ${headers}`);
173+
if (headers === undefined || !headers.includes(http_utils.CONTENT_TYPE_APP_FORM_URLENCODED)) {
174+
dbg.error(`verify_op_request_body_type: should have header ${http_utils.CONTENT_TYPE_APP_FORM_URLENCODED} ` +
175+
`in request, currently the headers are: ${headers}`);
177176
// GAP - need to make sure which error we need to throw
178177
throw new IamError(IamError.InvalidParameterValue);
179178
}

src/endpoint/s3/s3_rest.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ async function handle_request(req, res) {
114114
}
115115

116116
const op_name = parse_op_name(req);
117+
const op = s3_ops[op_name];
118+
if (!op || !op.handler) {
119+
dbg.error('S3 NotImplemented', op_name, req.method, req.originalUrl);
120+
throw new S3Error(S3Error.NotImplemented);
121+
}
117122
req.op_name = op_name;
118123

119124
http_utils.authorize_session_token(req, headers_options);
@@ -140,12 +145,6 @@ async function handle_request(req, res) {
140145
}
141146
}
142147

143-
const op = s3_ops[op_name];
144-
if (!op || !op.handler) {
145-
dbg.error('S3 TODO (NotImplemented)', op_name, req.method, req.originalUrl);
146-
throw new S3Error(S3Error.NotImplemented);
147-
}
148-
149148
const options = {
150149
body: op.body,
151150
reply: op.reply,

src/endpoint/sts/sts_rest.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ async function handle_request(req, res) {
8383
await http_utils.read_and_parse_body(req, options);
8484

8585
const op_name = parse_op_name(req, req.body.action);
86+
const op = STS_OPS[op_name];
87+
if (!op || !op.handler) {
88+
dbg.error('STS NotImplemented', op_name, req.method, req.originalUrl);
89+
throw new StsError(StsError.NotImplemented);
90+
}
8691
req.op_name = op_name;
8792

8893
http_utils.authorize_session_token(req, headers_options);
@@ -91,12 +96,6 @@ async function handle_request(req, res) {
9196

9297
dbg.log1('STS REQUEST', req.method, req.originalUrl, 'op', op_name, 'request_id', req.request_id, req.headers);
9398

94-
const op = STS_OPS[op_name];
95-
if (!op || !op.handler) {
96-
dbg.error('STS TODO (NotImplemented)', op_name, req.method, req.originalUrl);
97-
throw new StsError(StsError.NotImplemented);
98-
}
99-
10099
const reply = await op.handler(req, res);
101100
http_utils.send_reply(req, res, reply, {
102101
...options,

0 commit comments

Comments
 (0)