(node, expectedAttrs, msg)
| 45 | } |
| 46 | |
| 47 | function assertAnchorAttrs(node, expectedAttrs, msg) { |
| 48 | var a = node.select('a'); |
| 49 | |
| 50 | if(!expectedAttrs) expectedAttrs = {}; |
| 51 | |
| 52 | var WHITE_LIST = ['xlink:href', 'xlink:show', 'style', 'target', 'onclick']; |
| 53 | var attrs = listAttributes(a.node()); |
| 54 | |
| 55 | // check that no other attribute are found in anchor, |
| 56 | // which can be lead to XSS attacks. |
| 57 | |
| 58 | var wrongAttrs = []; |
| 59 | attrs.forEach(function(attr) { |
| 60 | if(WHITE_LIST.indexOf(attr) === -1) wrongAttrs.push(attr); |
| 61 | }); |
| 62 | |
| 63 | expect(wrongAttrs).toEqual([], msg); |
| 64 | |
| 65 | var style = expectedAttrs.style || ''; |
| 66 | var fullStyle = style || ''; |
| 67 | if(style) fullStyle += ';'; |
| 68 | fullStyle += 'cursor:pointer'; |
| 69 | |
| 70 | expect(a.attr('style')).toBe(fullStyle, msg); |
| 71 | |
| 72 | expect(a.attr('onclick')).toBe(expectedAttrs.onclick || null, msg); |
| 73 | } |
| 74 | |
| 75 | function listAttributes(node) { |
| 76 | var items = Array.prototype.slice.call(node.attributes); |
no test coverage detected
searching dependent graphs…