UNPKG

openhim-core

Version:

The OpenHIM core application that provides logging and routing of http requests

333 lines (332 loc) 12.3 kB
<!doctype html> <html lang="en"> <head> <title>Code coverage report for src/api/certificateAuthority.coffee</title> <meta charset="utf-8" /> <link rel="stylesheet" href="../../prettify.css" /> <link rel="stylesheet" href="../../base.css" /> <meta name="viewport" content="width=device-width, initial-scale=1"> <style type='text/css'> .coverage-summary .sorter { background-image: url(../../sort-arrow-sprite.png); } </style> </head> <body> <div class='wrapper'> <div class='pad1'> <h1> <a href="../../index.html">All files</a> / <a href="index.html">src/api</a> certificateAuthority.coffee </h1> <div class='clearfix'> <div class='fl pad1y space-right2'> <span class="strong">29.41% </span> <span class="quiet">Statements</span> <span class='fraction'>15/51</span> </div> <div class='fl pad1y space-right2'> <span class="strong">100% </span> <span class="quiet">Branches</span> <span class='fraction'>0/0</span> </div> <div class='fl pad1y space-right2'> <span class="strong">0% </span> <span class="quiet">Functions</span> <span class='fraction'>0/7</span> </div> <div class='fl pad1y space-right2'> <span class="strong">29.41% </span> <span class="quiet">Lines</span> <span class='fraction'>15/51</span> </div> </div> </div> <div class='status-line low'></div> <pre><table class="coverage"> <tr><td class="line-count quiet">1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90</td><td class="line-coverage quiet"><span class="cline-any cline-yes">1x</span> <span class="cline-any cline-yes">1x</span> <span class="cline-any cline-yes">1x</span> <span class="cline-any cline-yes">1x</span> <span class="cline-any cline-yes">1x</span> <span class="cline-any cline-yes">1x</span> <span class="cline-any cline-yes">1x</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">1x</span> <span class="cline-any cline-yes">1x</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">1x</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">1x</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">1x</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">1x</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">1x</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">1x</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">Keystore = require('../model/keystore').Keystore Certificate = require('../model/keystore').Certificate Q = require 'q' logger = require 'winston' utils = require "../utils" pem = require "pem" authorisation = require './authorisation' &nbsp; readCertificateInfo = Q.denodeify pem.readCertificateInfo getFingerprint = Q.denodeify pem.getFingerprint &nbsp; exports.generateCert = <span class="fstat-no" title="function not covered" ></span>-&gt; # Must be admin if authorisation.inGroup('admin', this.authenticated) is false <span class="cstat-no" title="statement not covered" > utils.logAndSetResponse this, 403, "User #{this.authenticated.email} is not an admin, API access to getServerKey by id denied.", 'info'</span> <span class="cstat-no" title="statement not covered" > return</span> &nbsp; <span class="cstat-no" title="statement not covered" > options = this.request.b</span>ody if options.type is 'server' <span class="cstat-no" title="statement not covered" > logger.info 'Generating server cert'</span> <span class="cstat-no" title="statement not covered" > result = yield generateServerCert options</span> else <span class="cstat-no" title="statement not covered" > logger.info 'Generating client cert'</span> <span class="cstat-no" title="statement not covered" > result = yield generateClientCert options</span> <span class="cstat-no" title="statement not covered" > this.status = 2</span>01 this.body = result &nbsp; generateClientCert = <span class="fstat-no" title="function not covered" >(</span>options) -&gt; <span class="cstat-no" title="statement not covered" > keystoreDoc = y</span>ield Keystore.findOne().exec() &nbsp; # Set additional options <span class="cstat-no" title="statement not covered" > options.selfSigned = t</span>rue &nbsp; # Attempt to create the certificate try <span class="cstat-no" title="statement not covered" > this.body = y</span>ield createCertificate options <span class="cstat-no" title="statement not covered" > certInfo = y</span>ield extractCertMetadata this.body.certificate <span class="cstat-no" title="statement not covered" > keystoreDoc.ca.push certInfo</span> <span class="cstat-no" title="statement not covered" > yield Q.ninvoke keystoreDoc, 'save'</span> #Add the new certficate to the keystore <span class="cstat-no" title="statement not covered" > this.status = 2</span>01 <span class="cstat-no" title="statement not covered" > logger.info 'Client certificate created'</span> catch <span class="cstat-no" title="statement not covered" >err</span> <span class="cstat-no" title="statement not covered" > utils.logAndSetResponse this, 'internal server error', "Could not create a client cert via the API: #{err}", 'error'</span> this.body &nbsp; generateServerCert = <span class="fstat-no" title="function not covered" >(</span>options) -&gt; <span class="cstat-no" title="statement not covered" > keystoreDoc = y</span>ield Keystore.findOne().exec() <span class="cstat-no" title="statement not covered" > options.selfSigned = t</span>rue try <span class="cstat-no" title="statement not covered" > this.body = y</span>ield createCertificate options <span class="cstat-no" title="statement not covered" > keystoreDoc.cert = y</span>ield extractCertMetadata this.body.certificate <span class="cstat-no" title="statement not covered" > keystoreDoc.key = this.body.k</span>ey <span class="cstat-no" title="statement not covered" > yield Q.ninvoke keystoreDoc, 'save'</span> #Add the new certficate to the keystore <span class="cstat-no" title="statement not covered" > this.status = 2</span>01 <span class="cstat-no" title="statement not covered" > logger.info 'Server certificate created'</span> &nbsp; catch <span class="cstat-no" title="statement not covered" >err</span> <span class="cstat-no" title="statement not covered" > utils.logAndSetResponse this, 'internal server error', "Could not create a client cert via the API: #{err}", 'error'</span> this.body &nbsp; createCertificate = <span class="fstat-no" title="function not covered" >(</span>options) -&gt; <span class="cstat-no" title="statement not covered" > deferred = Q</span>.defer() <span class="cstat-no" title="statement not covered" > pem.createCertificate options, <span class="fstat-no" title="function not covered" >(</span>err, cert) -&gt;</span> if (err) response = err : err deferred.resolve response else response = certificate : cert.certificate key : cert.clientKey deferred.resolve response &nbsp; <span class="cstat-no" title="statement not covered" > return deferred.p</span>romise &nbsp; extractCertMetadata = <span class="fstat-no" title="function not covered" >(</span>cert) -&gt; <span class="cstat-no" title="statement not covered" > certInfo = y</span>ield readCertificateInfo cert <span class="cstat-no" title="statement not covered" > fingerprint = y</span>ield getFingerprint cert <span class="cstat-no" title="statement not covered" > certInfo.data = this.body.c</span>ertificate <span class="cstat-no" title="statement not covered" > certInfo.fingerprint = fingerprint.f</span>ingerprint <span class="cstat-no" title="statement not covered" > return c</span>ertInfo &nbsp; getRandomInt = <span class="fstat-no" title="function not covered" >(</span>min, max) -&gt; Math.floor(Math.random() * (max - min + 1)) + min &nbsp; &nbsp; &nbsp; &nbsp;</pre></td></tr> </table></pre> <div class='push'></div><!-- for sticky footer --> </div><!-- /wrapper --> <div class='footer quiet pad2 space-top1 center small'> Code coverage generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Mon Oct 10 2016 13:39:22 GMT+0200 (SAST) </div> </div> <script src="../../prettify.js"></script> <script> window.onload = function () { if (typeof prettyPrint === 'function') { prettyPrint(); } }; </script> <script src="../../sorter.js"></script> </body> </html>