Skip to content

Commit 8c027ae

Browse files
authored
Merge pull request #41 from poloka/master
Fix verifyChallenge to properly handle and return the Promise.reject scenario
2 parents bd85584 + a21ab63 commit 8c027ae

File tree

6 files changed

+73
-19
lines changed

6 files changed

+73
-19
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,17 @@ XFC.Provider.init({
199199
})
200200
```
201201

202+
If the case of secret validation failures, acceptance is a new Error
203+
204+
```js
205+
XFC.Provider.init({
206+
acls: ['*'],
207+
secret: function(secret) {
208+
return Promise.reject(new Error('Failure'));
209+
}
210+
})
211+
```
212+
202213
If the app is using an alternate form a security and does require XFC to provide clickjacking support, a wildcard with no secret may be passed. Under these conditions, XFC will not hide the content and the consumer will automatically be authorized.
203214

204215
```js

example/initialization/1_b_index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,14 @@ <h2>launched app</h2>
5656
<h2>authorized app</h2>
5757
</div>
5858
</div>
59-
<p>The three examples below show usage of secret based authorization. This means that the origin of the URL does not matter. The first example shows that a string literal can be used as a secret. It shows that when the secret is incorrect, no content is displayed. The second example shows a working example using string literal secret that works. The third example shows that a secret function can be used to verify the secret.
59+
<p>The four examples below show usage of secret based authorization. This means that the origin of the URL does not matter. The first example shows that a string literal can be used as a secret. It shows that when the secret is incorrect, no content is displayed. The second example shows a working example using string literal secret that works. The third example shows that a secret function can be used to verify the secret. The fourth example shows how a failure response from the secret validation is handled and no content is displayed.
6060
</p>
6161
<script>
6262
XFC.Consumer.init()
6363
XFC.Consumer.mount(document.body, 'http://localprovider.com:8080/example/initialization/1_b_secret_string_literal.html', {secret: 'abc12367'});
6464
XFC.Consumer.mount(document.body, 'http://localprovider.com:8080/example/initialization/1_b_secret_string_literal.html', {secret: 'abc123'});
6565
XFC.Consumer.mount(document.body, 'http://localprovider.com:8080/example/initialization/1_b_secret_function.html', {secret: 'OAuth Header'});
66+
XFC.Consumer.mount(document.body, 'http://localprovider.com:8080/example/initialization/1_b_secret_function_failure.html', {secret: 'OAuth Header'});
6667
</script>
6768
</body>
6869
</html>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!DOCTYPE html>
2+
<html lang="en-us">
3+
<head>
4+
<title>HealtheLife Trusted Site</title>
5+
<meta charset="utf-8" />
6+
<style>
7+
body {
8+
padding-bottom: 5px;
9+
}
10+
html[hidden] { display: none; }
11+
</style>
12+
<script src="http://localhost:8080/xfc.js"></script>
13+
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/6.23.0/polyfill.min.js"></script>
14+
</head>
15+
<body>
16+
<div>
17+
<h1>1. Initialization</h1>
18+
<p>b. Enable parent frame authorization through a domain or a secret.</p>
19+
<p>i. The app can set the secret as a function.</p>
20+
</div>
21+
<script type="text/javascript">
22+
XFC.Provider.init({
23+
acls: ['*'],
24+
secret: function(secret) {
25+
return Promise.reject(new Error('Failure'));
26+
}
27+
});
28+
</script>
29+
</body>
30+
</html>

package-lock.json

Lines changed: 17 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/provider/application.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,9 @@ class Application extends EventEmitter {
246246
if (typeof this.secret === 'string' && fixedTimeCompare(this.secret, secretAttempt)) {
247247
authorize();
248248
} else if (typeof this.secret === 'function') {
249-
this.secret.call(this, secretAttempt).then(authorize);
249+
return this.secret.call(this, secretAttempt).then(authorize);
250250
}
251+
return Promise.resolve();
251252
}
252253

253254
/**

test/application.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,17 @@ describe('Application', () => {
199199

200200
application.verifyChallenge("123");
201201
});
202+
203+
it("handles failure from this.secret", (done) => {
204+
const error = new Error('promise rejected');
205+
const secret = (secretAttempt) => Promise.reject(error);
206+
application.init({secret});
207+
expect(application.emitError).to.have.been.called;
208+
application.verifyChallenge("123").catch((err) => {
209+
expect(err).to.equal(error);
210+
done();
211+
});
212+
});
202213
});
203214
});
204215

0 commit comments

Comments
 (0)