Skip to content

Commit 3eb7aa3

Browse files
authored
Merge pull request #105 from stellar/stellar-toml-increase-limit
Increase stellar.toml size limit, improve error message
2 parents e62d92b + 1a5a416 commit 3eb7aa3

4 files changed

+15
-4
lines changed

src/federation_server.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,11 @@ export class FederationServer {
170170
})
171171
.catch(response => {
172172
if (response instanceof Error) {
173-
return Promise.reject(response);
173+
if (response.message.match(/^maxContentLength size/)) {
174+
throw new Error(`federation response exceeds allowed size of ${FEDERATION_RESPONSE_MAX_SIZE}`);
175+
} else {
176+
return Promise.reject(response);
177+
}
174178
} else {
175179
return Promise.reject(new BadResponseError(`Server query failed. Server responded: ${response.status} ${response.statusText}`, response.data));
176180
}

src/stellar_toml_resolver.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import toml from 'toml';
44
import {Config} from "./config";
55

66
// STELLAR_TOML_MAX_SIZE is the maximum size of stellar.toml file
7-
export const STELLAR_TOML_MAX_SIZE = 5 * 1024;
7+
export const STELLAR_TOML_MAX_SIZE = 100 * 1024;
88

99
/**
1010
* StellarTomlResolver allows resolving `stellar.toml` files.
@@ -46,6 +46,13 @@ export class StellarTomlResolver {
4646
} catch (e) {
4747
return Promise.reject(new Error(`Parsing error on line ${e.line}, column ${e.column}: ${e.message}`));
4848
}
49+
})
50+
.catch(err => {
51+
if (err.message.match(/^maxContentLength size/)) {
52+
throw new Error(`stellar.toml file exceeds allowed size of ${STELLAR_TOML_MAX_SIZE}`);
53+
} else {
54+
throw err;
55+
}
4956
});
5057
}
5158
}

test/unit/federation_server_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ FEDERATION_SERVER="https://api.stellar.org/federation"
222222
}).listen(4444, () => {
223223
new StellarSdk.FederationServer('http://localhost:4444/federation', 'stellar.org', {allowHttp: true})
224224
.resolveAddress('bob*stellar.org')
225-
.should.be.rejectedWith(/maxContentLength size of [0-9]+ exceeded/)
225+
.should.be.rejectedWith(/federation response exceeds allowed size of [0-9]+/)
226226
.notify(done)
227227
.then(() => tempServer.close());
228228
});

test/unit/stellar_toml_resolver_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ FEDERATION_SERVER="https://api.stellar.org/federation"
101101
res.end(response);
102102
}).listen(4444, () => {
103103
StellarSdk.StellarTomlResolver.resolve("localhost:4444", {allowHttp: true})
104-
.should.be.rejectedWith(/maxContentLength size of [0-9]+ exceeded/)
104+
.should.be.rejectedWith(/stellar.toml file exceeds allowed size of [0-9]+/)
105105
.notify(done)
106106
.then(() => tempServer.close());
107107
});

0 commit comments

Comments
 (0)