Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Johann-S committed Aug 19, 2018
1 parent 82890e9 commit 9c4c72e
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 46 deletions.
17 changes: 1 addition & 16 deletions js/tests/unit/affix.js
Expand Up @@ -26,7 +26,7 @@ $(function () {

QUnit.test('should return jquery collection containing the element', function (assert) {
assert.expect(2)
var $el = $('<div/>')
var $el = $('<div/>').appendTo('#qunit-fixture')
var $affix = $el.bootstrapAffix()
assert.ok($affix instanceof $, 'returns jquery collection')
assert.strictEqual($affix[0], $el[0], 'collection contains element')
Expand Down Expand Up @@ -104,19 +104,4 @@ $(function () {
}, 250)
}, 250)
})

QUnit.test('should raise exception to avoid xss on target', function (assert) {
assert.expect(1)
assert.throws(function () {

var templateHTML = '<div id="affixTarget"></div>'
$(templateHTML).appendTo(document.body)

$('#affixTarget').bootstrapAffix({
target: '<img src=1 onerror=\'alert(0)\'>'
})

}, new Error('Syntax error, unrecognized expression: <img src=1 onerror=\'alert(0)\'>'))
})

})
11 changes: 0 additions & 11 deletions js/tests/unit/collapse.js
Expand Up @@ -439,15 +439,4 @@ $(function () {
})
.bootstrapCollapse('show')
})

QUnit.test('should raise exception to avoid xss on data-parent', function (assert) {
assert.expect(1)
assert.throws(function () {
$('<a role="button" data-toggle="collapse" data-parent="<img src=1 onerror=\'alert(0)\'>" href="#collapseThree">')
.appendTo('#qunit-fixture')
.bootstrapCollapse('show')
.trigger('click');
}, new Error('Syntax error, unrecognized expression: <img src=1 onerror=\'alert(0)\'>'))
})

})
19 changes: 0 additions & 19 deletions js/tests/unit/tooltip.js
Expand Up @@ -1321,23 +1321,4 @@ $(function () {
}
})
})

QUnit.test('should raise exception to avoid xss on data-container', function (assert) {
assert.expect(1)
assert.throws(function () {
$('<button data-toggle="tooltip" data-container="<img src=1 onerror=\'alert(0)\'>" title="Tooltip on right">Tooltip on right</button>')
.appendTo('#qunit-fixture')
.bootstrapTooltip('show')
}, new Error('Syntax error, unrecognized expression: <img src=1 onerror=\'alert(0)\'>'))
})

QUnit.test('should raise exception to avoid xss on data-viewport', function (assert) {
assert.expect(1)
assert.throws(function () {
$('<button data-toggle="tooltip" data-viewport="<img src=1 onerror=\'alert(0)\'>" title="Tooltip on right">Tooltip on right</button>')
.appendTo('#qunit-fixture')
.bootstrapTooltip('show')
}, new Error('Syntax error, unrecognized expression: <img src=1 onerror=\'alert(0)\'>'))
})

})
10 changes: 10 additions & 0 deletions js/tests/visual/affix.html
Expand Up @@ -54,6 +54,8 @@

<div class="page-header js-page-header">
<h1>Affix <small>Bootstrap Visual Test</small></h1>

<div id="affixTarget">Affix target with XSS</div>
</div>

<div class="col-md-3">
Expand Down Expand Up @@ -277,6 +279,14 @@ <h1>Affix <small>Bootstrap Visual Test</small></h1>
<!-- JavaScript Test -->
<script>
$(function () {
try {
$('#affixTarget').bootstrapAffix({
target: '<img src=1 onerror=\'alert(0)\'>'
})
} catch (e) {
console.error(e)
}

$('.js-affixed-element-top').affix({
offset: {
top: $('.js-page-header').outerHeight(true) - 10
Expand Down
4 changes: 4 additions & 0 deletions js/tests/visual/collapse.html
Expand Up @@ -69,6 +69,10 @@ <h4 class="panel-title">
<button class="btn" data-toggle="collapse" data-target="<img src=x onerror=alert(0)>">
Collapse with an XSS
</button>

<button class="btn" data-toggle="collapse" data-parent="<img src=1 onerror=\'alert(0)\'>" href="#collapseThree">
Collapse with an XSS in data-parent
</button>
</div>

<!-- JavaScript Includes -->
Expand Down
2 changes: 2 additions & 0 deletions js/tests/visual/tooltip.html
Expand Up @@ -30,6 +30,8 @@ <h1>Tooltip <small>Bootstrap Visual Test</small></h1>
<button type="button" class="btn btn-default" data-toggle="tooltip" data-placement="top" title="Tooltip on top">Tooltip on top</button>
<button type="button" class="btn btn-default" data-toggle="tooltip" data-placement="bottom" title="Tooltip on bottom">Tooltip on bottom</button>
<button type="button" class="btn btn-default" data-toggle="tooltip" data-placement="right" title="Tooltip on right">Tooltip on right</button>
<button type="button" class="btn btn-default" data-toggle="tooltip" data-container="<img src=1 onerror=\'alert(0)\'>" title="Tooltip on right">Tooltip with XSS on data-container</button>
<button type="button" class="btn btn-default" data-toggle="tooltip" data-viewport="<img src=1 onerror=\'alert(0)\'>" title="Tooltip on right">Tooltip with XSS on data-viewport</button>
</p>

</div>
Expand Down

0 comments on commit 9c4c72e

Please sign in to comment.