Skip to content

Commit

Permalink
Merge pull request #105 from stellar/stellar-toml-increase-limit
Browse files Browse the repository at this point in the history
Increase stellar.toml size limit, improve error message
  • Loading branch information
bartekn committed Nov 21, 2017
2 parents e62d92b + 1a5a416 commit 3eb7aa3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/federation_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,11 @@ export class FederationServer {
})
.catch(response => {
if (response instanceof Error) {
return Promise.reject(response);
if (response.message.match(/^maxContentLength size/)) {
throw new Error(`federation response exceeds allowed size of ${FEDERATION_RESPONSE_MAX_SIZE}`);
} else {
return Promise.reject(response);
}
} else {
return Promise.reject(new BadResponseError(`Server query failed. Server responded: ${response.status} ${response.statusText}`, response.data));
}
Expand Down
9 changes: 8 additions & 1 deletion src/stellar_toml_resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import toml from 'toml';
import {Config} from "./config";

// STELLAR_TOML_MAX_SIZE is the maximum size of stellar.toml file
export const STELLAR_TOML_MAX_SIZE = 5 * 1024;
export const STELLAR_TOML_MAX_SIZE = 100 * 1024;

/**
* StellarTomlResolver allows resolving `stellar.toml` files.
Expand Down Expand Up @@ -46,6 +46,13 @@ export class StellarTomlResolver {
} catch (e) {
return Promise.reject(new Error(`Parsing error on line ${e.line}, column ${e.column}: ${e.message}`));
}
})
.catch(err => {
if (err.message.match(/^maxContentLength size/)) {
throw new Error(`stellar.toml file exceeds allowed size of ${STELLAR_TOML_MAX_SIZE}`);
} else {
throw err;
}
});
}
}
2 changes: 1 addition & 1 deletion test/unit/federation_server_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ FEDERATION_SERVER="https://api.stellar.org/federation"
}).listen(4444, () => {
new StellarSdk.FederationServer('http://localhost:4444/federation', 'stellar.org', {allowHttp: true})
.resolveAddress('bob*stellar.org')
.should.be.rejectedWith(/maxContentLength size of [0-9]+ exceeded/)
.should.be.rejectedWith(/federation response exceeds allowed size of [0-9]+/)
.notify(done)
.then(() => tempServer.close());
});
Expand Down
2 changes: 1 addition & 1 deletion test/unit/stellar_toml_resolver_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ FEDERATION_SERVER="https://api.stellar.org/federation"
res.end(response);
}).listen(4444, () => {
StellarSdk.StellarTomlResolver.resolve("localhost:4444", {allowHttp: true})
.should.be.rejectedWith(/maxContentLength size of [0-9]+ exceeded/)
.should.be.rejectedWith(/stellar.toml file exceeds allowed size of [0-9]+/)
.notify(done)
.then(() => tempServer.close());
});
Expand Down

0 comments on commit 3eb7aa3

Please sign in to comment.