mirror of
https://github.com/brianc/node-postgres.git
synced 2026-01-18 15:55:05 +00:00
Absorb pg-pass library
This commit is contained in:
parent
264e30f424
commit
d393979a22
@ -0,0 +1 @@
|
||||
{}
|
||||
File diff suppressed because one or more lines are too long
@ -0,0 +1 @@
|
||||
{"parent":null,"pid":54647,"argv":["/Users/brian.carlson/.volta/tools/image/node/22.14.0/bin/node","/Users/brian.carlson/.volta/tools/image/yarn/1.22.22/bin/yarn.js","run","_test"],"execArgv":[],"cwd":"/Users/brian.carlson/src/node-postgres/packages/pg-pass","time":1745947035694,"ppid":54646,"coverageFilename":"/Users/brian.carlson/src/node-postgres/packages/pg-pass/.nyc_output/4a578060-c3d8-43f8-83f9-3a80ee8b79c2.json","externalId":"","uuid":"4a578060-c3d8-43f8-83f9-3a80ee8b79c2","files":[]}
|
||||
@ -0,0 +1 @@
|
||||
{"parent":"4a578060-c3d8-43f8-83f9-3a80ee8b79c2","pid":54648,"argv":["/Users/brian.carlson/.volta/tools/image/node/22.14.0/bin/node","/Users/brian.carlson/src/node-postgres/packages/pg-pass/node_modules/.bin/mocha","--recursive","-R","list"],"execArgv":[],"cwd":"/Users/brian.carlson/src/node-postgres/packages/pg-pass","time":1745947036080,"ppid":54647,"coverageFilename":"/Users/brian.carlson/src/node-postgres/packages/pg-pass/.nyc_output/5139fd5f-dbfc-44bb-ae8a-17e6962e23cd.json","externalId":"","uuid":"5139fd5f-dbfc-44bb-ae8a-17e6962e23cd","files":["/Users/brian.carlson/src/node-postgres/packages/pg-pass/lib/index.js","/Users/brian.carlson/src/node-postgres/packages/pg-pass/lib/helper.js"]}
|
||||
1
packages/pg-pass/.nyc_output/processinfo/index.json
Normal file
1
packages/pg-pass/.nyc_output/processinfo/index.json
Normal file
@ -0,0 +1 @@
|
||||
{"processes":{"4a578060-c3d8-43f8-83f9-3a80ee8b79c2":{"parent":null,"children":["5139fd5f-dbfc-44bb-ae8a-17e6962e23cd"]},"5139fd5f-dbfc-44bb-ae8a-17e6962e23cd":{"parent":"4a578060-c3d8-43f8-83f9-3a80ee8b79c2","children":[]}},"files":{"/Users/brian.carlson/src/node-postgres/packages/pg-pass/lib/index.js":["5139fd5f-dbfc-44bb-ae8a-17e6962e23cd"],"/Users/brian.carlson/src/node-postgres/packages/pg-pass/lib/helper.js":["5139fd5f-dbfc-44bb-ae8a-17e6962e23cd"]},"externalIds":{}}
|
||||
74
packages/pg-pass/README.md
Normal file
74
packages/pg-pass/README.md
Normal file
@ -0,0 +1,74 @@
|
||||
# pgpass
|
||||
|
||||
[](https://github.com/hoegaarden/pgpass/actions?query=workflow%3ACI+branch%3Amaster)
|
||||
|
||||
## Install
|
||||
|
||||
```sh
|
||||
npm install pgpass
|
||||
```
|
||||
|
||||
## Usage
|
||||
```js
|
||||
var pgPass = require('pgpass');
|
||||
|
||||
var connInfo = {
|
||||
'host' : 'pgserver' ,
|
||||
'user' : 'the_user_name' ,
|
||||
};
|
||||
|
||||
pgPass(connInfo, function(pass){
|
||||
conn_info.password = pass;
|
||||
// connect to postgresql server
|
||||
});
|
||||
```
|
||||
|
||||
## Description
|
||||
|
||||
This module tries to read the `~/.pgpass` file (or the equivalent for windows systems). If the environment variable `PGPASSFILE` is set, this file is used instead. If everything goes right, the password from said file is passed to the callback; if the password cannot be read `undefined` is passed to the callback.
|
||||
|
||||
Cases where `undefined` is returned:
|
||||
|
||||
- the environment variable `PGPASSWORD` is set
|
||||
- the file cannot be read (wrong permissions, no such file, ...)
|
||||
- for non windows systems: the file is write-/readable by the group or by other users
|
||||
- there is no matching line for the given connection info
|
||||
|
||||
There should be no need to use this module directly; it is already included in `node-postgres`.
|
||||
|
||||
## Configuration
|
||||
|
||||
The module reads the environment variable `PGPASS_NO_DEESCAPE` to decide if the the read tokens from the password file should be de-escaped or not. Default is to do de-escaping. For further information on this see [this commit](https://github.com/postgres/postgres/commit/8d15e3ec4fcb735875a8a70a09ec0c62153c3329).
|
||||
|
||||
|
||||
## Tests
|
||||
|
||||
There are tests in `./test/`; including linting and coverage testing. Running `npm test` runs:
|
||||
|
||||
- `jshint`
|
||||
- `mocha` tests
|
||||
- `jscoverage` and `mocha -R html-cov`
|
||||
|
||||
You can see the coverage report in `coverage.html`.
|
||||
|
||||
|
||||
## Development, Patches, Bugs, ...
|
||||
|
||||
If you find Bugs or have improvements, please feel free to open a issue on GitHub. If you provide a pull request, I'm more than happy to merge them, just make sure to add tests for your changes.
|
||||
|
||||
## Links
|
||||
|
||||
- https://github.com/hoegaarden/node-pgpass
|
||||
- http://www.postgresql.org/docs/current/static/libpq-pgpass.html
|
||||
- https://wiki.postgresql.org/wiki/Pgpass
|
||||
- https://github.com/postgres/postgres/blob/master/src/interfaces/libpq/fe-connect.c
|
||||
|
||||
## License
|
||||
|
||||
Copyright (c) 2013-2016 Hannes Hörl
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
224
packages/pg-pass/coverage/base.css
Normal file
224
packages/pg-pass/coverage/base.css
Normal file
@ -0,0 +1,224 @@
|
||||
body, html {
|
||||
margin:0; padding: 0;
|
||||
height: 100%;
|
||||
}
|
||||
body {
|
||||
font-family: Helvetica Neue, Helvetica, Arial;
|
||||
font-size: 14px;
|
||||
color:#333;
|
||||
}
|
||||
.small { font-size: 12px; }
|
||||
*, *:after, *:before {
|
||||
-webkit-box-sizing:border-box;
|
||||
-moz-box-sizing:border-box;
|
||||
box-sizing:border-box;
|
||||
}
|
||||
h1 { font-size: 20px; margin: 0;}
|
||||
h2 { font-size: 14px; }
|
||||
pre {
|
||||
font: 12px/1.4 Consolas, "Liberation Mono", Menlo, Courier, monospace;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
-moz-tab-size: 2;
|
||||
-o-tab-size: 2;
|
||||
tab-size: 2;
|
||||
}
|
||||
a { color:#0074D9; text-decoration:none; }
|
||||
a:hover { text-decoration:underline; }
|
||||
.strong { font-weight: bold; }
|
||||
.space-top1 { padding: 10px 0 0 0; }
|
||||
.pad2y { padding: 20px 0; }
|
||||
.pad1y { padding: 10px 0; }
|
||||
.pad2x { padding: 0 20px; }
|
||||
.pad2 { padding: 20px; }
|
||||
.pad1 { padding: 10px; }
|
||||
.space-left2 { padding-left:55px; }
|
||||
.space-right2 { padding-right:20px; }
|
||||
.center { text-align:center; }
|
||||
.clearfix { display:block; }
|
||||
.clearfix:after {
|
||||
content:'';
|
||||
display:block;
|
||||
height:0;
|
||||
clear:both;
|
||||
visibility:hidden;
|
||||
}
|
||||
.fl { float: left; }
|
||||
@media only screen and (max-width:640px) {
|
||||
.col3 { width:100%; max-width:100%; }
|
||||
.hide-mobile { display:none!important; }
|
||||
}
|
||||
|
||||
.quiet {
|
||||
color: #7f7f7f;
|
||||
color: rgba(0,0,0,0.5);
|
||||
}
|
||||
.quiet a { opacity: 0.7; }
|
||||
|
||||
.fraction {
|
||||
font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace;
|
||||
font-size: 10px;
|
||||
color: #555;
|
||||
background: #E8E8E8;
|
||||
padding: 4px 5px;
|
||||
border-radius: 3px;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
div.path a:link, div.path a:visited { color: #333; }
|
||||
table.coverage {
|
||||
border-collapse: collapse;
|
||||
margin: 10px 0 0 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
table.coverage td {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
vertical-align: top;
|
||||
}
|
||||
table.coverage td.line-count {
|
||||
text-align: right;
|
||||
padding: 0 5px 0 20px;
|
||||
}
|
||||
table.coverage td.line-coverage {
|
||||
text-align: right;
|
||||
padding-right: 10px;
|
||||
min-width:20px;
|
||||
}
|
||||
|
||||
table.coverage td span.cline-any {
|
||||
display: inline-block;
|
||||
padding: 0 5px;
|
||||
width: 100%;
|
||||
}
|
||||
.missing-if-branch {
|
||||
display: inline-block;
|
||||
margin-right: 5px;
|
||||
border-radius: 3px;
|
||||
position: relative;
|
||||
padding: 0 4px;
|
||||
background: #333;
|
||||
color: yellow;
|
||||
}
|
||||
|
||||
.skip-if-branch {
|
||||
display: none;
|
||||
margin-right: 10px;
|
||||
position: relative;
|
||||
padding: 0 4px;
|
||||
background: #ccc;
|
||||
color: white;
|
||||
}
|
||||
.missing-if-branch .typ, .skip-if-branch .typ {
|
||||
color: inherit !important;
|
||||
}
|
||||
.coverage-summary {
|
||||
border-collapse: collapse;
|
||||
width: 100%;
|
||||
}
|
||||
.coverage-summary tr { border-bottom: 1px solid #bbb; }
|
||||
.keyline-all { border: 1px solid #ddd; }
|
||||
.coverage-summary td, .coverage-summary th { padding: 10px; }
|
||||
.coverage-summary tbody { border: 1px solid #bbb; }
|
||||
.coverage-summary td { border-right: 1px solid #bbb; }
|
||||
.coverage-summary td:last-child { border-right: none; }
|
||||
.coverage-summary th {
|
||||
text-align: left;
|
||||
font-weight: normal;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.coverage-summary th.file { border-right: none !important; }
|
||||
.coverage-summary th.pct { }
|
||||
.coverage-summary th.pic,
|
||||
.coverage-summary th.abs,
|
||||
.coverage-summary td.pct,
|
||||
.coverage-summary td.abs { text-align: right; }
|
||||
.coverage-summary td.file { white-space: nowrap; }
|
||||
.coverage-summary td.pic { min-width: 120px !important; }
|
||||
.coverage-summary tfoot td { }
|
||||
|
||||
.coverage-summary .sorter {
|
||||
height: 10px;
|
||||
width: 7px;
|
||||
display: inline-block;
|
||||
margin-left: 0.5em;
|
||||
background: url(sort-arrow-sprite.png) no-repeat scroll 0 0 transparent;
|
||||
}
|
||||
.coverage-summary .sorted .sorter {
|
||||
background-position: 0 -20px;
|
||||
}
|
||||
.coverage-summary .sorted-desc .sorter {
|
||||
background-position: 0 -10px;
|
||||
}
|
||||
.status-line { height: 10px; }
|
||||
/* yellow */
|
||||
.cbranch-no { background: yellow !important; color: #111; }
|
||||
/* dark red */
|
||||
.red.solid, .status-line.low, .low .cover-fill { background:#C21F39 }
|
||||
.low .chart { border:1px solid #C21F39 }
|
||||
.highlighted,
|
||||
.highlighted .cstat-no, .highlighted .fstat-no, .highlighted .cbranch-no{
|
||||
background: #C21F39 !important;
|
||||
}
|
||||
/* medium red */
|
||||
.cstat-no, .fstat-no, .cbranch-no, .cbranch-no { background:#F6C6CE }
|
||||
/* light red */
|
||||
.low, .cline-no { background:#FCE1E5 }
|
||||
/* light green */
|
||||
.high, .cline-yes { background:rgb(230,245,208) }
|
||||
/* medium green */
|
||||
.cstat-yes { background:rgb(161,215,106) }
|
||||
/* dark green */
|
||||
.status-line.high, .high .cover-fill { background:rgb(77,146,33) }
|
||||
.high .chart { border:1px solid rgb(77,146,33) }
|
||||
/* dark yellow (gold) */
|
||||
.status-line.medium, .medium .cover-fill { background: #f9cd0b; }
|
||||
.medium .chart { border:1px solid #f9cd0b; }
|
||||
/* light yellow */
|
||||
.medium { background: #fff4c2; }
|
||||
|
||||
.cstat-skip { background: #ddd; color: #111; }
|
||||
.fstat-skip { background: #ddd; color: #111 !important; }
|
||||
.cbranch-skip { background: #ddd !important; color: #111; }
|
||||
|
||||
span.cline-neutral { background: #eaeaea; }
|
||||
|
||||
.coverage-summary td.empty {
|
||||
opacity: .5;
|
||||
padding-top: 4px;
|
||||
padding-bottom: 4px;
|
||||
line-height: 1;
|
||||
color: #888;
|
||||
}
|
||||
|
||||
.cover-fill, .cover-empty {
|
||||
display:inline-block;
|
||||
height: 12px;
|
||||
}
|
||||
.chart {
|
||||
line-height: 0;
|
||||
}
|
||||
.cover-empty {
|
||||
background: white;
|
||||
}
|
||||
.cover-full {
|
||||
border-right: none !important;
|
||||
}
|
||||
pre.prettyprint {
|
||||
border: none !important;
|
||||
padding: 0 !important;
|
||||
margin: 0 !important;
|
||||
}
|
||||
.com { color: #999 !important; }
|
||||
.ignore-none { color: #999; font-weight: normal; }
|
||||
|
||||
.wrapper {
|
||||
min-height: 100%;
|
||||
height: auto !important;
|
||||
height: 100%;
|
||||
margin: 0 auto -48px;
|
||||
}
|
||||
.footer, .push {
|
||||
height: 48px;
|
||||
}
|
||||
87
packages/pg-pass/coverage/block-navigation.js
Normal file
87
packages/pg-pass/coverage/block-navigation.js
Normal file
@ -0,0 +1,87 @@
|
||||
/* eslint-disable */
|
||||
var jumpToCode = (function init() {
|
||||
// Classes of code we would like to highlight in the file view
|
||||
var missingCoverageClasses = ['.cbranch-no', '.cstat-no', '.fstat-no'];
|
||||
|
||||
// Elements to highlight in the file listing view
|
||||
var fileListingElements = ['td.pct.low'];
|
||||
|
||||
// We don't want to select elements that are direct descendants of another match
|
||||
var notSelector = ':not(' + missingCoverageClasses.join('):not(') + ') > '; // becomes `:not(a):not(b) > `
|
||||
|
||||
// Selecter that finds elements on the page to which we can jump
|
||||
var selector =
|
||||
fileListingElements.join(', ') +
|
||||
', ' +
|
||||
notSelector +
|
||||
missingCoverageClasses.join(', ' + notSelector); // becomes `:not(a):not(b) > a, :not(a):not(b) > b`
|
||||
|
||||
// The NodeList of matching elements
|
||||
var missingCoverageElements = document.querySelectorAll(selector);
|
||||
|
||||
var currentIndex;
|
||||
|
||||
function toggleClass(index) {
|
||||
missingCoverageElements
|
||||
.item(currentIndex)
|
||||
.classList.remove('highlighted');
|
||||
missingCoverageElements.item(index).classList.add('highlighted');
|
||||
}
|
||||
|
||||
function makeCurrent(index) {
|
||||
toggleClass(index);
|
||||
currentIndex = index;
|
||||
missingCoverageElements.item(index).scrollIntoView({
|
||||
behavior: 'smooth',
|
||||
block: 'center',
|
||||
inline: 'center'
|
||||
});
|
||||
}
|
||||
|
||||
function goToPrevious() {
|
||||
var nextIndex = 0;
|
||||
if (typeof currentIndex !== 'number' || currentIndex === 0) {
|
||||
nextIndex = missingCoverageElements.length - 1;
|
||||
} else if (missingCoverageElements.length > 1) {
|
||||
nextIndex = currentIndex - 1;
|
||||
}
|
||||
|
||||
makeCurrent(nextIndex);
|
||||
}
|
||||
|
||||
function goToNext() {
|
||||
var nextIndex = 0;
|
||||
|
||||
if (
|
||||
typeof currentIndex === 'number' &&
|
||||
currentIndex < missingCoverageElements.length - 1
|
||||
) {
|
||||
nextIndex = currentIndex + 1;
|
||||
}
|
||||
|
||||
makeCurrent(nextIndex);
|
||||
}
|
||||
|
||||
return function jump(event) {
|
||||
if (
|
||||
document.getElementById('fileSearch') === document.activeElement &&
|
||||
document.activeElement != null
|
||||
) {
|
||||
// if we're currently focused on the search input, we don't want to navigate
|
||||
return;
|
||||
}
|
||||
|
||||
switch (event.which) {
|
||||
case 78: // n
|
||||
case 74: // j
|
||||
goToNext();
|
||||
break;
|
||||
case 66: // b
|
||||
case 75: // k
|
||||
case 80: // p
|
||||
goToPrevious();
|
||||
break;
|
||||
}
|
||||
};
|
||||
})();
|
||||
window.addEventListener('keydown', jumpToCode);
|
||||
BIN
packages/pg-pass/coverage/favicon.png
Normal file
BIN
packages/pg-pass/coverage/favicon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 445 B |
697
packages/pg-pass/coverage/helper.js.html
Normal file
697
packages/pg-pass/coverage/helper.js.html
Normal file
@ -0,0 +1,697 @@
|
||||
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<title>Code coverage report for helper.js</title>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="stylesheet" href="prettify.css" />
|
||||
<link rel="stylesheet" href="base.css" />
|
||||
<link rel="shortcut icon" type="image/x-icon" href="favicon.png" />
|
||||
<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> helper.js</h1>
|
||||
<div class='clearfix'>
|
||||
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">100% </span>
|
||||
<span class="quiet">Statements</span>
|
||||
<span class='fraction'>110/110</span>
|
||||
</div>
|
||||
|
||||
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">100% </span>
|
||||
<span class="quiet">Branches</span>
|
||||
<span class='fraction'>65/65</span>
|
||||
</div>
|
||||
|
||||
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">100% </span>
|
||||
<span class="quiet">Functions</span>
|
||||
<span class='fraction'>21/21</span>
|
||||
</div>
|
||||
|
||||
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">100% </span>
|
||||
<span class="quiet">Lines</span>
|
||||
<span class='fraction'>108/108</span>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
<p class="quiet">
|
||||
Press <em>n</em> or <em>j</em> to go to the next uncovered block, <em>b</em>, <em>p</em> or <em>k</em> for the previous block.
|
||||
</p>
|
||||
<template id="filterTemplate">
|
||||
<div class="quiet">
|
||||
Filter:
|
||||
<input type="search" id="fileSearch">
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
<div class='status-line high'></div>
|
||||
<pre><table class="coverage">
|
||||
<tr><td class="line-count quiet"><a name='L1'></a><a href='#L1'>1</a>
|
||||
<a name='L2'></a><a href='#L2'>2</a>
|
||||
<a name='L3'></a><a href='#L3'>3</a>
|
||||
<a name='L4'></a><a href='#L4'>4</a>
|
||||
<a name='L5'></a><a href='#L5'>5</a>
|
||||
<a name='L6'></a><a href='#L6'>6</a>
|
||||
<a name='L7'></a><a href='#L7'>7</a>
|
||||
<a name='L8'></a><a href='#L8'>8</a>
|
||||
<a name='L9'></a><a href='#L9'>9</a>
|
||||
<a name='L10'></a><a href='#L10'>10</a>
|
||||
<a name='L11'></a><a href='#L11'>11</a>
|
||||
<a name='L12'></a><a href='#L12'>12</a>
|
||||
<a name='L13'></a><a href='#L13'>13</a>
|
||||
<a name='L14'></a><a href='#L14'>14</a>
|
||||
<a name='L15'></a><a href='#L15'>15</a>
|
||||
<a name='L16'></a><a href='#L16'>16</a>
|
||||
<a name='L17'></a><a href='#L17'>17</a>
|
||||
<a name='L18'></a><a href='#L18'>18</a>
|
||||
<a name='L19'></a><a href='#L19'>19</a>
|
||||
<a name='L20'></a><a href='#L20'>20</a>
|
||||
<a name='L21'></a><a href='#L21'>21</a>
|
||||
<a name='L22'></a><a href='#L22'>22</a>
|
||||
<a name='L23'></a><a href='#L23'>23</a>
|
||||
<a name='L24'></a><a href='#L24'>24</a>
|
||||
<a name='L25'></a><a href='#L25'>25</a>
|
||||
<a name='L26'></a><a href='#L26'>26</a>
|
||||
<a name='L27'></a><a href='#L27'>27</a>
|
||||
<a name='L28'></a><a href='#L28'>28</a>
|
||||
<a name='L29'></a><a href='#L29'>29</a>
|
||||
<a name='L30'></a><a href='#L30'>30</a>
|
||||
<a name='L31'></a><a href='#L31'>31</a>
|
||||
<a name='L32'></a><a href='#L32'>32</a>
|
||||
<a name='L33'></a><a href='#L33'>33</a>
|
||||
<a name='L34'></a><a href='#L34'>34</a>
|
||||
<a name='L35'></a><a href='#L35'>35</a>
|
||||
<a name='L36'></a><a href='#L36'>36</a>
|
||||
<a name='L37'></a><a href='#L37'>37</a>
|
||||
<a name='L38'></a><a href='#L38'>38</a>
|
||||
<a name='L39'></a><a href='#L39'>39</a>
|
||||
<a name='L40'></a><a href='#L40'>40</a>
|
||||
<a name='L41'></a><a href='#L41'>41</a>
|
||||
<a name='L42'></a><a href='#L42'>42</a>
|
||||
<a name='L43'></a><a href='#L43'>43</a>
|
||||
<a name='L44'></a><a href='#L44'>44</a>
|
||||
<a name='L45'></a><a href='#L45'>45</a>
|
||||
<a name='L46'></a><a href='#L46'>46</a>
|
||||
<a name='L47'></a><a href='#L47'>47</a>
|
||||
<a name='L48'></a><a href='#L48'>48</a>
|
||||
<a name='L49'></a><a href='#L49'>49</a>
|
||||
<a name='L50'></a><a href='#L50'>50</a>
|
||||
<a name='L51'></a><a href='#L51'>51</a>
|
||||
<a name='L52'></a><a href='#L52'>52</a>
|
||||
<a name='L53'></a><a href='#L53'>53</a>
|
||||
<a name='L54'></a><a href='#L54'>54</a>
|
||||
<a name='L55'></a><a href='#L55'>55</a>
|
||||
<a name='L56'></a><a href='#L56'>56</a>
|
||||
<a name='L57'></a><a href='#L57'>57</a>
|
||||
<a name='L58'></a><a href='#L58'>58</a>
|
||||
<a name='L59'></a><a href='#L59'>59</a>
|
||||
<a name='L60'></a><a href='#L60'>60</a>
|
||||
<a name='L61'></a><a href='#L61'>61</a>
|
||||
<a name='L62'></a><a href='#L62'>62</a>
|
||||
<a name='L63'></a><a href='#L63'>63</a>
|
||||
<a name='L64'></a><a href='#L64'>64</a>
|
||||
<a name='L65'></a><a href='#L65'>65</a>
|
||||
<a name='L66'></a><a href='#L66'>66</a>
|
||||
<a name='L67'></a><a href='#L67'>67</a>
|
||||
<a name='L68'></a><a href='#L68'>68</a>
|
||||
<a name='L69'></a><a href='#L69'>69</a>
|
||||
<a name='L70'></a><a href='#L70'>70</a>
|
||||
<a name='L71'></a><a href='#L71'>71</a>
|
||||
<a name='L72'></a><a href='#L72'>72</a>
|
||||
<a name='L73'></a><a href='#L73'>73</a>
|
||||
<a name='L74'></a><a href='#L74'>74</a>
|
||||
<a name='L75'></a><a href='#L75'>75</a>
|
||||
<a name='L76'></a><a href='#L76'>76</a>
|
||||
<a name='L77'></a><a href='#L77'>77</a>
|
||||
<a name='L78'></a><a href='#L78'>78</a>
|
||||
<a name='L79'></a><a href='#L79'>79</a>
|
||||
<a name='L80'></a><a href='#L80'>80</a>
|
||||
<a name='L81'></a><a href='#L81'>81</a>
|
||||
<a name='L82'></a><a href='#L82'>82</a>
|
||||
<a name='L83'></a><a href='#L83'>83</a>
|
||||
<a name='L84'></a><a href='#L84'>84</a>
|
||||
<a name='L85'></a><a href='#L85'>85</a>
|
||||
<a name='L86'></a><a href='#L86'>86</a>
|
||||
<a name='L87'></a><a href='#L87'>87</a>
|
||||
<a name='L88'></a><a href='#L88'>88</a>
|
||||
<a name='L89'></a><a href='#L89'>89</a>
|
||||
<a name='L90'></a><a href='#L90'>90</a>
|
||||
<a name='L91'></a><a href='#L91'>91</a>
|
||||
<a name='L92'></a><a href='#L92'>92</a>
|
||||
<a name='L93'></a><a href='#L93'>93</a>
|
||||
<a name='L94'></a><a href='#L94'>94</a>
|
||||
<a name='L95'></a><a href='#L95'>95</a>
|
||||
<a name='L96'></a><a href='#L96'>96</a>
|
||||
<a name='L97'></a><a href='#L97'>97</a>
|
||||
<a name='L98'></a><a href='#L98'>98</a>
|
||||
<a name='L99'></a><a href='#L99'>99</a>
|
||||
<a name='L100'></a><a href='#L100'>100</a>
|
||||
<a name='L101'></a><a href='#L101'>101</a>
|
||||
<a name='L102'></a><a href='#L102'>102</a>
|
||||
<a name='L103'></a><a href='#L103'>103</a>
|
||||
<a name='L104'></a><a href='#L104'>104</a>
|
||||
<a name='L105'></a><a href='#L105'>105</a>
|
||||
<a name='L106'></a><a href='#L106'>106</a>
|
||||
<a name='L107'></a><a href='#L107'>107</a>
|
||||
<a name='L108'></a><a href='#L108'>108</a>
|
||||
<a name='L109'></a><a href='#L109'>109</a>
|
||||
<a name='L110'></a><a href='#L110'>110</a>
|
||||
<a name='L111'></a><a href='#L111'>111</a>
|
||||
<a name='L112'></a><a href='#L112'>112</a>
|
||||
<a name='L113'></a><a href='#L113'>113</a>
|
||||
<a name='L114'></a><a href='#L114'>114</a>
|
||||
<a name='L115'></a><a href='#L115'>115</a>
|
||||
<a name='L116'></a><a href='#L116'>116</a>
|
||||
<a name='L117'></a><a href='#L117'>117</a>
|
||||
<a name='L118'></a><a href='#L118'>118</a>
|
||||
<a name='L119'></a><a href='#L119'>119</a>
|
||||
<a name='L120'></a><a href='#L120'>120</a>
|
||||
<a name='L121'></a><a href='#L121'>121</a>
|
||||
<a name='L122'></a><a href='#L122'>122</a>
|
||||
<a name='L123'></a><a href='#L123'>123</a>
|
||||
<a name='L124'></a><a href='#L124'>124</a>
|
||||
<a name='L125'></a><a href='#L125'>125</a>
|
||||
<a name='L126'></a><a href='#L126'>126</a>
|
||||
<a name='L127'></a><a href='#L127'>127</a>
|
||||
<a name='L128'></a><a href='#L128'>128</a>
|
||||
<a name='L129'></a><a href='#L129'>129</a>
|
||||
<a name='L130'></a><a href='#L130'>130</a>
|
||||
<a name='L131'></a><a href='#L131'>131</a>
|
||||
<a name='L132'></a><a href='#L132'>132</a>
|
||||
<a name='L133'></a><a href='#L133'>133</a>
|
||||
<a name='L134'></a><a href='#L134'>134</a>
|
||||
<a name='L135'></a><a href='#L135'>135</a>
|
||||
<a name='L136'></a><a href='#L136'>136</a>
|
||||
<a name='L137'></a><a href='#L137'>137</a>
|
||||
<a name='L138'></a><a href='#L138'>138</a>
|
||||
<a name='L139'></a><a href='#L139'>139</a>
|
||||
<a name='L140'></a><a href='#L140'>140</a>
|
||||
<a name='L141'></a><a href='#L141'>141</a>
|
||||
<a name='L142'></a><a href='#L142'>142</a>
|
||||
<a name='L143'></a><a href='#L143'>143</a>
|
||||
<a name='L144'></a><a href='#L144'>144</a>
|
||||
<a name='L145'></a><a href='#L145'>145</a>
|
||||
<a name='L146'></a><a href='#L146'>146</a>
|
||||
<a name='L147'></a><a href='#L147'>147</a>
|
||||
<a name='L148'></a><a href='#L148'>148</a>
|
||||
<a name='L149'></a><a href='#L149'>149</a>
|
||||
<a name='L150'></a><a href='#L150'>150</a>
|
||||
<a name='L151'></a><a href='#L151'>151</a>
|
||||
<a name='L152'></a><a href='#L152'>152</a>
|
||||
<a name='L153'></a><a href='#L153'>153</a>
|
||||
<a name='L154'></a><a href='#L154'>154</a>
|
||||
<a name='L155'></a><a href='#L155'>155</a>
|
||||
<a name='L156'></a><a href='#L156'>156</a>
|
||||
<a name='L157'></a><a href='#L157'>157</a>
|
||||
<a name='L158'></a><a href='#L158'>158</a>
|
||||
<a name='L159'></a><a href='#L159'>159</a>
|
||||
<a name='L160'></a><a href='#L160'>160</a>
|
||||
<a name='L161'></a><a href='#L161'>161</a>
|
||||
<a name='L162'></a><a href='#L162'>162</a>
|
||||
<a name='L163'></a><a href='#L163'>163</a>
|
||||
<a name='L164'></a><a href='#L164'>164</a>
|
||||
<a name='L165'></a><a href='#L165'>165</a>
|
||||
<a name='L166'></a><a href='#L166'>166</a>
|
||||
<a name='L167'></a><a href='#L167'>167</a>
|
||||
<a name='L168'></a><a href='#L168'>168</a>
|
||||
<a name='L169'></a><a href='#L169'>169</a>
|
||||
<a name='L170'></a><a href='#L170'>170</a>
|
||||
<a name='L171'></a><a href='#L171'>171</a>
|
||||
<a name='L172'></a><a href='#L172'>172</a>
|
||||
<a name='L173'></a><a href='#L173'>173</a>
|
||||
<a name='L174'></a><a href='#L174'>174</a>
|
||||
<a name='L175'></a><a href='#L175'>175</a>
|
||||
<a name='L176'></a><a href='#L176'>176</a>
|
||||
<a name='L177'></a><a href='#L177'>177</a>
|
||||
<a name='L178'></a><a href='#L178'>178</a>
|
||||
<a name='L179'></a><a href='#L179'>179</a>
|
||||
<a name='L180'></a><a href='#L180'>180</a>
|
||||
<a name='L181'></a><a href='#L181'>181</a>
|
||||
<a name='L182'></a><a href='#L182'>182</a>
|
||||
<a name='L183'></a><a href='#L183'>183</a>
|
||||
<a name='L184'></a><a href='#L184'>184</a>
|
||||
<a name='L185'></a><a href='#L185'>185</a>
|
||||
<a name='L186'></a><a href='#L186'>186</a>
|
||||
<a name='L187'></a><a href='#L187'>187</a>
|
||||
<a name='L188'></a><a href='#L188'>188</a>
|
||||
<a name='L189'></a><a href='#L189'>189</a>
|
||||
<a name='L190'></a><a href='#L190'>190</a>
|
||||
<a name='L191'></a><a href='#L191'>191</a>
|
||||
<a name='L192'></a><a href='#L192'>192</a>
|
||||
<a name='L193'></a><a href='#L193'>193</a>
|
||||
<a name='L194'></a><a href='#L194'>194</a>
|
||||
<a name='L195'></a><a href='#L195'>195</a>
|
||||
<a name='L196'></a><a href='#L196'>196</a>
|
||||
<a name='L197'></a><a href='#L197'>197</a>
|
||||
<a name='L198'></a><a href='#L198'>198</a>
|
||||
<a name='L199'></a><a href='#L199'>199</a>
|
||||
<a name='L200'></a><a href='#L200'>200</a>
|
||||
<a name='L201'></a><a href='#L201'>201</a>
|
||||
<a name='L202'></a><a href='#L202'>202</a>
|
||||
<a name='L203'></a><a href='#L203'>203</a>
|
||||
<a name='L204'></a><a href='#L204'>204</a>
|
||||
<a name='L205'></a><a href='#L205'>205</a></td><td class="line-coverage quiet"><span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </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"> </span>
|
||||
<span class="cline-any cline-yes">1x</span>
|
||||
<span class="cline-any cline-neutral"> </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"> </span>
|
||||
<span class="cline-any cline-yes">12x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </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"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">7x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">7x</span>
|
||||
<span class="cline-any cline-yes">6x</span>
|
||||
<span class="cline-any cline-yes">6x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">1x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">7x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">9x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">1x</span>
|
||||
<span class="cline-any cline-yes">5x</span>
|
||||
<span class="cline-any cline-yes">5x</span>
|
||||
<span class="cline-any cline-yes">5x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">1x</span>
|
||||
<span class="cline-any cline-yes">10x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">10x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">10x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">1x</span>
|
||||
<span class="cline-any cline-yes">15x</span>
|
||||
<span class="cline-any cline-yes">2x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">13x</span>
|
||||
<span class="cline-any cline-yes">1x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">12x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">12x</span>
|
||||
<span class="cline-any cline-yes">4x</span>
|
||||
<span class="cline-any cline-yes">4x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">8x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">2x</span>
|
||||
<span class="cline-any cline-yes">2x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">6x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">1x</span>
|
||||
<span class="cline-any cline-yes">24x</span>
|
||||
<span class="cline-any cline-yes">96x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">24x</span>
|
||||
<span class="cline-any cline-yes">1x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">95x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">1x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">7x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">44x</span>
|
||||
<span class="cline-any cline-yes">44x</span>
|
||||
<span class="cline-any cline-yes">5x</span>
|
||||
<span class="cline-any cline-yes">5x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">7x</span>
|
||||
<span class="cline-any cline-yes">6x</span>
|
||||
<span class="cline-any cline-yes">6x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">7x</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"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">7x</span>
|
||||
<span class="cline-any cline-yes">7x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">1x</span>
|
||||
<span class="cline-any cline-yes">51x</span>
|
||||
<span class="cline-any cline-yes">19x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">32x</span>
|
||||
<span class="cline-any cline-yes">32x</span>
|
||||
<span class="cline-any cline-yes">32x</span>
|
||||
<span class="cline-any cline-yes">32x</span>
|
||||
<span class="cline-any cline-yes">32x</span>
|
||||
<span class="cline-any cline-yes">32x</span>
|
||||
<span class="cline-any cline-yes">32x</span>
|
||||
<span class="cline-any cline-yes">135x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">135x</span>
|
||||
<span class="cline-any cline-yes">110x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">135x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">32x</span>
|
||||
<span class="cline-any cline-yes">681x</span>
|
||||
<span class="cline-any cline-yes">681x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">681x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">681x</span>
|
||||
<span class="cline-any cline-yes">26x</span>
|
||||
<span class="cline-any cline-yes">26x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">655x</span>
|
||||
<span class="cline-any cline-yes">109x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">109x</span>
|
||||
<span class="cline-any cline-yes">109x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">32x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">32x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">1x</span>
|
||||
<span class="cline-any cline-yes">29x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">29x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">28x</span>
|
||||
<span class="cline-any cline-yes">15x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">13x</span>
|
||||
<span class="cline-any cline-yes">13x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">27x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">27x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">27x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">29x</span>
|
||||
<span class="cline-any cline-yes">138x</span>
|
||||
<span class="cline-any cline-yes">138x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">138x</span>
|
||||
<span class="cline-any cline-yes">138x</span>
|
||||
<span class="cline-any cline-yes">3x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">26x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span></td><td class="text"><pre class="prettyprint lang-js">'use strict'
|
||||
|
||||
const path = require('path'),
|
||||
Stream = require('stream').Stream,
|
||||
split = require('split2'),
|
||||
util = require('util'),
|
||||
defaultPort = 5432
|
||||
|
||||
let warnStream = process.stderr
|
||||
|
||||
let isWin = process.platform === 'win32'
|
||||
const S_IRWXG = 56, // 00070(8)
|
||||
S_IRWXO = 7, // 00007(8)
|
||||
S_IFMT = 61440, // 00170000(8)
|
||||
S_IFREG = 32768 // 0100000(8)
|
||||
function isRegFile(mode) {
|
||||
return (mode & S_IFMT) == S_IFREG
|
||||
}
|
||||
|
||||
const fieldNames = ['host', 'port', 'database', 'user', 'password']
|
||||
const nrOfFields = fieldNames.length
|
||||
const passKey = fieldNames[nrOfFields - 1]
|
||||
|
||||
function warn() {
|
||||
const isWritable = warnStream instanceof Stream && true === warnStream.writable
|
||||
|
||||
if (isWritable) {
|
||||
const args = Array.prototype.slice.call(arguments).concat('\n')
|
||||
warnStream.write(util.format.apply(util, args))
|
||||
}
|
||||
}
|
||||
|
||||
Object.defineProperty(module.exports, 'isWin', {
|
||||
get: function () {
|
||||
return isWin
|
||||
},
|
||||
set: function (val) {
|
||||
isWin = val
|
||||
},
|
||||
})
|
||||
|
||||
module.exports.warnTo = function (stream) {
|
||||
const old = warnStream
|
||||
warnStream = stream
|
||||
return old
|
||||
}
|
||||
|
||||
module.exports.getFileName = function (rawEnv) {
|
||||
const env = rawEnv || process.env
|
||||
const file =
|
||||
env.PGPASSFILE ||
|
||||
(isWin ? path.join(env.APPDATA || './', 'postgresql', 'pgpass.conf') : path.join(env.HOME || './', '.pgpass'))
|
||||
return file
|
||||
}
|
||||
|
||||
module.exports.usePgPass = function (stats, fname) {
|
||||
if (Object.prototype.hasOwnProperty.call(process.env, 'PGPASSWORD')) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (isWin) {
|
||||
return true
|
||||
}
|
||||
|
||||
fname = fname || '<unkn>'
|
||||
|
||||
if (!isRegFile(stats.mode)) {
|
||||
warn('WARNING: password file "%s" is not a plain file', fname)
|
||||
return false
|
||||
}
|
||||
|
||||
if (stats.mode & (S_IRWXG | S_IRWXO)) {
|
||||
/* If password file is insecure, alert the user and ignore it. */
|
||||
warn('WARNING: password file "%s" has group or world access; permissions should be u=rw (0600) or less', fname)
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
const matcher = (module.exports.match = function (connInfo, entry) {
|
||||
return fieldNames.slice(0, -1).reduce(function (prev, field, idx) {
|
||||
if (idx == 1) {
|
||||
// the port
|
||||
if (Number(connInfo[field] || defaultPort) === Number(entry[field])) {
|
||||
return prev && true
|
||||
}
|
||||
}
|
||||
return prev && (entry[field] === '*' || entry[field] === connInfo[field])
|
||||
}, true)
|
||||
})
|
||||
|
||||
module.exports.getPassword = function (connInfo, stream, cb) {
|
||||
let pass
|
||||
const lineStream = stream.pipe(split())
|
||||
|
||||
function onLine(line) {
|
||||
const entry = parseLine(line)
|
||||
if (entry && isValidEntry(entry) && matcher(connInfo, entry)) {
|
||||
pass = entry[passKey]
|
||||
lineStream.end() // -> calls onEnd(), but pass is set now
|
||||
}
|
||||
}
|
||||
|
||||
const onEnd = function () {
|
||||
stream.destroy()
|
||||
cb(pass)
|
||||
}
|
||||
|
||||
const onErr = function (err) {
|
||||
stream.destroy()
|
||||
warn('WARNING: error on reading file: %s', err)
|
||||
cb(undefined)
|
||||
}
|
||||
|
||||
stream.on('error', onErr)
|
||||
lineStream.on('data', onLine).on('end', onEnd).on('error', onErr)
|
||||
}
|
||||
|
||||
const parseLine = (module.exports.parseLine = function (line) {
|
||||
if (line.length < 11 || line.match(/^\s+#/)) {
|
||||
return null
|
||||
}
|
||||
|
||||
let curChar = ''
|
||||
let prevChar = ''
|
||||
let fieldIdx = 0
|
||||
let startIdx = 0
|
||||
let obj = {}
|
||||
let isLastField = false
|
||||
const addToObj = function (idx, i0, i1) {
|
||||
let field = line.substring(i0, i1)
|
||||
|
||||
if (!Object.hasOwnProperty.call(process.env, 'PGPASS_NO_DEESCAPE')) {
|
||||
field = field.replace(/\\([:\\])/g, '$1')
|
||||
}
|
||||
|
||||
obj[fieldNames[idx]] = field
|
||||
}
|
||||
|
||||
for (let i = 0; i < line.length - 1; i += 1) {
|
||||
curChar = line.charAt(i + 1)
|
||||
prevChar = line.charAt(i)
|
||||
|
||||
isLastField = fieldIdx == nrOfFields - 1
|
||||
|
||||
if (isLastField) {
|
||||
addToObj(fieldIdx, startIdx)
|
||||
break
|
||||
}
|
||||
|
||||
if (i >= 0 && curChar == ':' && prevChar !== '\\') {
|
||||
addToObj(fieldIdx, startIdx, i + 1)
|
||||
|
||||
startIdx = i + 2
|
||||
fieldIdx += 1
|
||||
}
|
||||
}
|
||||
|
||||
obj = Object.keys(obj).length === nrOfFields ? obj : null
|
||||
|
||||
return obj
|
||||
})
|
||||
|
||||
const isValidEntry = (module.exports.isValidEntry = function (entry) {
|
||||
const rules = {
|
||||
// host
|
||||
0: function (x) {
|
||||
return x.length > 0
|
||||
},
|
||||
// port
|
||||
1: function (x) {
|
||||
if (x === '*') {
|
||||
return true
|
||||
}
|
||||
x = Number(x)
|
||||
return isFinite(x) && x > 0 && x < 9007199254740992 && Math.floor(x) === x
|
||||
},
|
||||
// database
|
||||
2: function (x) {
|
||||
return x.length > 0
|
||||
},
|
||||
// username
|
||||
3: function (x) {
|
||||
return x.length > 0
|
||||
},
|
||||
// password
|
||||
4: function (x) {
|
||||
return x.length > 0
|
||||
},
|
||||
}
|
||||
|
||||
for (let idx = 0; idx < fieldNames.length; idx += 1) {
|
||||
const rule = rules[idx]
|
||||
const value = entry[fieldNames[idx]] || ''
|
||||
|
||||
const res = rule(value)
|
||||
if (!res) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
})
|
||||
</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="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
||||
at 2025-04-29T17:17:16.447Z
|
||||
</div>
|
||||
<script src="prettify.js"></script>
|
||||
<script>
|
||||
window.onload = function () {
|
||||
prettyPrint();
|
||||
};
|
||||
</script>
|
||||
<script src="sorter.js"></script>
|
||||
<script src="block-navigation.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
131
packages/pg-pass/coverage/index.html
Normal file
131
packages/pg-pass/coverage/index.html
Normal file
@ -0,0 +1,131 @@
|
||||
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<title>Code coverage report for All files</title>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="stylesheet" href="prettify.css" />
|
||||
<link rel="stylesheet" href="base.css" />
|
||||
<link rel="shortcut icon" type="image/x-icon" href="favicon.png" />
|
||||
<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>All files</h1>
|
||||
<div class='clearfix'>
|
||||
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">100% </span>
|
||||
<span class="quiet">Statements</span>
|
||||
<span class='fraction'>120/120</span>
|
||||
</div>
|
||||
|
||||
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">100% </span>
|
||||
<span class="quiet">Branches</span>
|
||||
<span class='fraction'>69/69</span>
|
||||
</div>
|
||||
|
||||
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">100% </span>
|
||||
<span class="quiet">Functions</span>
|
||||
<span class='fraction'>23/23</span>
|
||||
</div>
|
||||
|
||||
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">100% </span>
|
||||
<span class="quiet">Lines</span>
|
||||
<span class='fraction'>118/118</span>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
<p class="quiet">
|
||||
Press <em>n</em> or <em>j</em> to go to the next uncovered block, <em>b</em>, <em>p</em> or <em>k</em> for the previous block.
|
||||
</p>
|
||||
<template id="filterTemplate">
|
||||
<div class="quiet">
|
||||
Filter:
|
||||
<input type="search" id="fileSearch">
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
<div class='status-line high'></div>
|
||||
<div class="pad1">
|
||||
<table class="coverage-summary">
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-col="file" data-fmt="html" data-html="true" class="file">File</th>
|
||||
<th data-col="pic" data-type="number" data-fmt="html" data-html="true" class="pic"></th>
|
||||
<th data-col="statements" data-type="number" data-fmt="pct" class="pct">Statements</th>
|
||||
<th data-col="statements_raw" data-type="number" data-fmt="html" class="abs"></th>
|
||||
<th data-col="branches" data-type="number" data-fmt="pct" class="pct">Branches</th>
|
||||
<th data-col="branches_raw" data-type="number" data-fmt="html" class="abs"></th>
|
||||
<th data-col="functions" data-type="number" data-fmt="pct" class="pct">Functions</th>
|
||||
<th data-col="functions_raw" data-type="number" data-fmt="html" class="abs"></th>
|
||||
<th data-col="lines" data-type="number" data-fmt="pct" class="pct">Lines</th>
|
||||
<th data-col="lines_raw" data-type="number" data-fmt="html" class="abs"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr>
|
||||
<td class="file high" data-value="helper.js"><a href="helper.js.html">helper.js</a></td>
|
||||
<td data-value="100" class="pic high">
|
||||
<div class="chart"><div class="cover-fill cover-full" style="width: 100%"></div><div class="cover-empty" style="width: 0%"></div></div>
|
||||
</td>
|
||||
<td data-value="100" class="pct high">100%</td>
|
||||
<td data-value="110" class="abs high">110/110</td>
|
||||
<td data-value="100" class="pct high">100%</td>
|
||||
<td data-value="65" class="abs high">65/65</td>
|
||||
<td data-value="100" class="pct high">100%</td>
|
||||
<td data-value="21" class="abs high">21/21</td>
|
||||
<td data-value="100" class="pct high">100%</td>
|
||||
<td data-value="108" class="abs high">108/108</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td class="file high" data-value="index.js"><a href="index.js.html">index.js</a></td>
|
||||
<td data-value="100" class="pic high">
|
||||
<div class="chart"><div class="cover-fill cover-full" style="width: 100%"></div><div class="cover-empty" style="width: 0%"></div></div>
|
||||
</td>
|
||||
<td data-value="100" class="pct high">100%</td>
|
||||
<td data-value="10" class="abs high">10/10</td>
|
||||
<td data-value="100" class="pct high">100%</td>
|
||||
<td data-value="4" class="abs high">4/4</td>
|
||||
<td data-value="100" class="pct high">100%</td>
|
||||
<td data-value="2" class="abs high">2/2</td>
|
||||
<td data-value="100" class="pct high">100%</td>
|
||||
<td data-value="10" class="abs high">10/10</td>
|
||||
</tr>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class='push'></div><!-- for sticky footer -->
|
||||
</div><!-- /wrapper -->
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage generated by
|
||||
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
||||
at 2025-04-29T17:17:16.447Z
|
||||
</div>
|
||||
<script src="prettify.js"></script>
|
||||
<script>
|
||||
window.onload = function () {
|
||||
prettyPrint();
|
||||
};
|
||||
</script>
|
||||
<script src="sorter.js"></script>
|
||||
<script src="block-navigation.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
142
packages/pg-pass/coverage/index.js.html
Normal file
142
packages/pg-pass/coverage/index.js.html
Normal file
@ -0,0 +1,142 @@
|
||||
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<title>Code coverage report for index.js</title>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="stylesheet" href="prettify.css" />
|
||||
<link rel="stylesheet" href="base.css" />
|
||||
<link rel="shortcut icon" type="image/x-icon" href="favicon.png" />
|
||||
<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> index.js</h1>
|
||||
<div class='clearfix'>
|
||||
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">100% </span>
|
||||
<span class="quiet">Statements</span>
|
||||
<span class='fraction'>10/10</span>
|
||||
</div>
|
||||
|
||||
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">100% </span>
|
||||
<span class="quiet">Branches</span>
|
||||
<span class='fraction'>4/4</span>
|
||||
</div>
|
||||
|
||||
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">100% </span>
|
||||
<span class="quiet">Functions</span>
|
||||
<span class='fraction'>2/2</span>
|
||||
</div>
|
||||
|
||||
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">100% </span>
|
||||
<span class="quiet">Lines</span>
|
||||
<span class='fraction'>10/10</span>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
<p class="quiet">
|
||||
Press <em>n</em> or <em>j</em> to go to the next uncovered block, <em>b</em>, <em>p</em> or <em>k</em> for the previous block.
|
||||
</p>
|
||||
<template id="filterTemplate">
|
||||
<div class="quiet">
|
||||
Filter:
|
||||
<input type="search" id="fileSearch">
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
<div class='status-line high'></div>
|
||||
<pre><table class="coverage">
|
||||
<tr><td class="line-count quiet"><a name='L1'></a><a href='#L1'>1</a>
|
||||
<a name='L2'></a><a href='#L2'>2</a>
|
||||
<a name='L3'></a><a href='#L3'>3</a>
|
||||
<a name='L4'></a><a href='#L4'>4</a>
|
||||
<a name='L5'></a><a href='#L5'>5</a>
|
||||
<a name='L6'></a><a href='#L6'>6</a>
|
||||
<a name='L7'></a><a href='#L7'>7</a>
|
||||
<a name='L8'></a><a href='#L8'>8</a>
|
||||
<a name='L9'></a><a href='#L9'>9</a>
|
||||
<a name='L10'></a><a href='#L10'>10</a>
|
||||
<a name='L11'></a><a href='#L11'>11</a>
|
||||
<a name='L12'></a><a href='#L12'>12</a>
|
||||
<a name='L13'></a><a href='#L13'>13</a>
|
||||
<a name='L14'></a><a href='#L14'>14</a>
|
||||
<a name='L15'></a><a href='#L15'>15</a>
|
||||
<a name='L16'></a><a href='#L16'>16</a>
|
||||
<a name='L17'></a><a href='#L17'>17</a>
|
||||
<a name='L18'></a><a href='#L18'>18</a>
|
||||
<a name='L19'></a><a href='#L19'>19</a>
|
||||
<a name='L20'></a><a href='#L20'>20</a></td><td class="line-coverage quiet"><span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </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">6x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">6x</span>
|
||||
<span class="cline-any cline-yes">6x</span>
|
||||
<span class="cline-any cline-yes">2x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">4x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">4x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">1x</span>
|
||||
<span class="cline-any cline-neutral"> </span></td><td class="text"><pre class="prettyprint lang-js">'use strict'
|
||||
|
||||
const fs = require('fs'),
|
||||
helper = require('./helper.js')
|
||||
module.exports = function (connInfo, cb) {
|
||||
const file = helper.getFileName()
|
||||
|
||||
fs.stat(file, function (err, stat) {
|
||||
if (err || !helper.usePgPass(stat, file)) {
|
||||
return cb(undefined)
|
||||
}
|
||||
|
||||
const st = fs.createReadStream(file)
|
||||
|
||||
helper.getPassword(connInfo, st, cb)
|
||||
})
|
||||
}
|
||||
|
||||
module.exports.warnTo = helper.warnTo
|
||||
</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="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
||||
at 2025-04-29T17:17:16.447Z
|
||||
</div>
|
||||
<script src="prettify.js"></script>
|
||||
<script>
|
||||
window.onload = function () {
|
||||
prettyPrint();
|
||||
};
|
||||
</script>
|
||||
<script src="sorter.js"></script>
|
||||
<script src="block-navigation.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
1
packages/pg-pass/coverage/prettify.css
Normal file
1
packages/pg-pass/coverage/prettify.css
Normal file
@ -0,0 +1 @@
|
||||
.pln{color:#000}@media screen{.str{color:#080}.kwd{color:#008}.com{color:#800}.typ{color:#606}.lit{color:#066}.pun,.opn,.clo{color:#660}.tag{color:#008}.atn{color:#606}.atv{color:#080}.dec,.var{color:#606}.fun{color:red}}@media print,projection{.str{color:#060}.kwd{color:#006;font-weight:bold}.com{color:#600;font-style:italic}.typ{color:#404;font-weight:bold}.lit{color:#044}.pun,.opn,.clo{color:#440}.tag{color:#006;font-weight:bold}.atn{color:#404}.atv{color:#060}}pre.prettyprint{padding:2px;border:1px solid #888}ol.linenums{margin-top:0;margin-bottom:0}li.L0,li.L1,li.L2,li.L3,li.L5,li.L6,li.L7,li.L8{list-style-type:none}li.L1,li.L3,li.L5,li.L7,li.L9{background:#eee}
|
||||
2
packages/pg-pass/coverage/prettify.js
Normal file
2
packages/pg-pass/coverage/prettify.js
Normal file
File diff suppressed because one or more lines are too long
BIN
packages/pg-pass/coverage/sort-arrow-sprite.png
Normal file
BIN
packages/pg-pass/coverage/sort-arrow-sprite.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 138 B |
196
packages/pg-pass/coverage/sorter.js
Normal file
196
packages/pg-pass/coverage/sorter.js
Normal file
@ -0,0 +1,196 @@
|
||||
/* eslint-disable */
|
||||
var addSorting = (function() {
|
||||
'use strict';
|
||||
var cols,
|
||||
currentSort = {
|
||||
index: 0,
|
||||
desc: false
|
||||
};
|
||||
|
||||
// returns the summary table element
|
||||
function getTable() {
|
||||
return document.querySelector('.coverage-summary');
|
||||
}
|
||||
// returns the thead element of the summary table
|
||||
function getTableHeader() {
|
||||
return getTable().querySelector('thead tr');
|
||||
}
|
||||
// returns the tbody element of the summary table
|
||||
function getTableBody() {
|
||||
return getTable().querySelector('tbody');
|
||||
}
|
||||
// returns the th element for nth column
|
||||
function getNthColumn(n) {
|
||||
return getTableHeader().querySelectorAll('th')[n];
|
||||
}
|
||||
|
||||
function onFilterInput() {
|
||||
const searchValue = document.getElementById('fileSearch').value;
|
||||
const rows = document.getElementsByTagName('tbody')[0].children;
|
||||
for (let i = 0; i < rows.length; i++) {
|
||||
const row = rows[i];
|
||||
if (
|
||||
row.textContent
|
||||
.toLowerCase()
|
||||
.includes(searchValue.toLowerCase())
|
||||
) {
|
||||
row.style.display = '';
|
||||
} else {
|
||||
row.style.display = 'none';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// loads the search box
|
||||
function addSearchBox() {
|
||||
var template = document.getElementById('filterTemplate');
|
||||
var templateClone = template.content.cloneNode(true);
|
||||
templateClone.getElementById('fileSearch').oninput = onFilterInput;
|
||||
template.parentElement.appendChild(templateClone);
|
||||
}
|
||||
|
||||
// loads all columns
|
||||
function loadColumns() {
|
||||
var colNodes = getTableHeader().querySelectorAll('th'),
|
||||
colNode,
|
||||
cols = [],
|
||||
col,
|
||||
i;
|
||||
|
||||
for (i = 0; i < colNodes.length; i += 1) {
|
||||
colNode = colNodes[i];
|
||||
col = {
|
||||
key: colNode.getAttribute('data-col'),
|
||||
sortable: !colNode.getAttribute('data-nosort'),
|
||||
type: colNode.getAttribute('data-type') || 'string'
|
||||
};
|
||||
cols.push(col);
|
||||
if (col.sortable) {
|
||||
col.defaultDescSort = col.type === 'number';
|
||||
colNode.innerHTML =
|
||||
colNode.innerHTML + '<span class="sorter"></span>';
|
||||
}
|
||||
}
|
||||
return cols;
|
||||
}
|
||||
// attaches a data attribute to every tr element with an object
|
||||
// of data values keyed by column name
|
||||
function loadRowData(tableRow) {
|
||||
var tableCols = tableRow.querySelectorAll('td'),
|
||||
colNode,
|
||||
col,
|
||||
data = {},
|
||||
i,
|
||||
val;
|
||||
for (i = 0; i < tableCols.length; i += 1) {
|
||||
colNode = tableCols[i];
|
||||
col = cols[i];
|
||||
val = colNode.getAttribute('data-value');
|
||||
if (col.type === 'number') {
|
||||
val = Number(val);
|
||||
}
|
||||
data[col.key] = val;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
// loads all row data
|
||||
function loadData() {
|
||||
var rows = getTableBody().querySelectorAll('tr'),
|
||||
i;
|
||||
|
||||
for (i = 0; i < rows.length; i += 1) {
|
||||
rows[i].data = loadRowData(rows[i]);
|
||||
}
|
||||
}
|
||||
// sorts the table using the data for the ith column
|
||||
function sortByIndex(index, desc) {
|
||||
var key = cols[index].key,
|
||||
sorter = function(a, b) {
|
||||
a = a.data[key];
|
||||
b = b.data[key];
|
||||
return a < b ? -1 : a > b ? 1 : 0;
|
||||
},
|
||||
finalSorter = sorter,
|
||||
tableBody = document.querySelector('.coverage-summary tbody'),
|
||||
rowNodes = tableBody.querySelectorAll('tr'),
|
||||
rows = [],
|
||||
i;
|
||||
|
||||
if (desc) {
|
||||
finalSorter = function(a, b) {
|
||||
return -1 * sorter(a, b);
|
||||
};
|
||||
}
|
||||
|
||||
for (i = 0; i < rowNodes.length; i += 1) {
|
||||
rows.push(rowNodes[i]);
|
||||
tableBody.removeChild(rowNodes[i]);
|
||||
}
|
||||
|
||||
rows.sort(finalSorter);
|
||||
|
||||
for (i = 0; i < rows.length; i += 1) {
|
||||
tableBody.appendChild(rows[i]);
|
||||
}
|
||||
}
|
||||
// removes sort indicators for current column being sorted
|
||||
function removeSortIndicators() {
|
||||
var col = getNthColumn(currentSort.index),
|
||||
cls = col.className;
|
||||
|
||||
cls = cls.replace(/ sorted$/, '').replace(/ sorted-desc$/, '');
|
||||
col.className = cls;
|
||||
}
|
||||
// adds sort indicators for current column being sorted
|
||||
function addSortIndicators() {
|
||||
getNthColumn(currentSort.index).className += currentSort.desc
|
||||
? ' sorted-desc'
|
||||
: ' sorted';
|
||||
}
|
||||
// adds event listeners for all sorter widgets
|
||||
function enableUI() {
|
||||
var i,
|
||||
el,
|
||||
ithSorter = function ithSorter(i) {
|
||||
var col = cols[i];
|
||||
|
||||
return function() {
|
||||
var desc = col.defaultDescSort;
|
||||
|
||||
if (currentSort.index === i) {
|
||||
desc = !currentSort.desc;
|
||||
}
|
||||
sortByIndex(i, desc);
|
||||
removeSortIndicators();
|
||||
currentSort.index = i;
|
||||
currentSort.desc = desc;
|
||||
addSortIndicators();
|
||||
};
|
||||
};
|
||||
for (i = 0; i < cols.length; i += 1) {
|
||||
if (cols[i].sortable) {
|
||||
// add the click event handler on the th so users
|
||||
// dont have to click on those tiny arrows
|
||||
el = getNthColumn(i).querySelector('.sorter').parentElement;
|
||||
if (el.addEventListener) {
|
||||
el.addEventListener('click', ithSorter(i));
|
||||
} else {
|
||||
el.attachEvent('onclick', ithSorter(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// adds sorting functionality to the UI
|
||||
return function() {
|
||||
if (!getTable()) {
|
||||
return;
|
||||
}
|
||||
cols = loadColumns();
|
||||
loadData();
|
||||
addSearchBox();
|
||||
addSortIndicators();
|
||||
enableUI();
|
||||
};
|
||||
})();
|
||||
|
||||
window.addEventListener('load', addSorting);
|
||||
204
packages/pg-pass/lib/helper.js
Normal file
204
packages/pg-pass/lib/helper.js
Normal file
@ -0,0 +1,204 @@
|
||||
'use strict'
|
||||
|
||||
const path = require('path'),
|
||||
Stream = require('stream').Stream,
|
||||
split = require('split2'),
|
||||
util = require('util'),
|
||||
defaultPort = 5432
|
||||
|
||||
let warnStream = process.stderr
|
||||
|
||||
let isWin = process.platform === 'win32'
|
||||
const S_IRWXG = 56, // 00070(8)
|
||||
S_IRWXO = 7, // 00007(8)
|
||||
S_IFMT = 61440, // 00170000(8)
|
||||
S_IFREG = 32768 // 0100000(8)
|
||||
function isRegFile(mode) {
|
||||
return (mode & S_IFMT) == S_IFREG
|
||||
}
|
||||
|
||||
const fieldNames = ['host', 'port', 'database', 'user', 'password']
|
||||
const nrOfFields = fieldNames.length
|
||||
const passKey = fieldNames[nrOfFields - 1]
|
||||
|
||||
function warn() {
|
||||
const isWritable = warnStream instanceof Stream && true === warnStream.writable
|
||||
|
||||
if (isWritable) {
|
||||
const args = Array.prototype.slice.call(arguments).concat('\n')
|
||||
warnStream.write(util.format.apply(util, args))
|
||||
}
|
||||
}
|
||||
|
||||
Object.defineProperty(module.exports, 'isWin', {
|
||||
get: function () {
|
||||
return isWin
|
||||
},
|
||||
set: function (val) {
|
||||
isWin = val
|
||||
},
|
||||
})
|
||||
|
||||
module.exports.warnTo = function (stream) {
|
||||
const old = warnStream
|
||||
warnStream = stream
|
||||
return old
|
||||
}
|
||||
|
||||
module.exports.getFileName = function (rawEnv) {
|
||||
const env = rawEnv || process.env
|
||||
const file =
|
||||
env.PGPASSFILE ||
|
||||
(isWin ? path.join(env.APPDATA || './', 'postgresql', 'pgpass.conf') : path.join(env.HOME || './', '.pgpass'))
|
||||
return file
|
||||
}
|
||||
|
||||
module.exports.usePgPass = function (stats, fname) {
|
||||
if (Object.prototype.hasOwnProperty.call(process.env, 'PGPASSWORD')) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (isWin) {
|
||||
return true
|
||||
}
|
||||
|
||||
fname = fname || '<unkn>'
|
||||
|
||||
if (!isRegFile(stats.mode)) {
|
||||
warn('WARNING: password file "%s" is not a plain file', fname)
|
||||
return false
|
||||
}
|
||||
|
||||
if (stats.mode & (S_IRWXG | S_IRWXO)) {
|
||||
/* If password file is insecure, alert the user and ignore it. */
|
||||
warn('WARNING: password file "%s" has group or world access; permissions should be u=rw (0600) or less', fname)
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
const matcher = (module.exports.match = function (connInfo, entry) {
|
||||
return fieldNames.slice(0, -1).reduce(function (prev, field, idx) {
|
||||
if (idx == 1) {
|
||||
// the port
|
||||
if (Number(connInfo[field] || defaultPort) === Number(entry[field])) {
|
||||
return prev && true
|
||||
}
|
||||
}
|
||||
return prev && (entry[field] === '*' || entry[field] === connInfo[field])
|
||||
}, true)
|
||||
})
|
||||
|
||||
module.exports.getPassword = function (connInfo, stream, cb) {
|
||||
let pass
|
||||
const lineStream = stream.pipe(split())
|
||||
|
||||
function onLine(line) {
|
||||
const entry = parseLine(line)
|
||||
if (entry && isValidEntry(entry) && matcher(connInfo, entry)) {
|
||||
pass = entry[passKey]
|
||||
lineStream.end() // -> calls onEnd(), but pass is set now
|
||||
}
|
||||
}
|
||||
|
||||
const onEnd = function () {
|
||||
stream.destroy()
|
||||
cb(pass)
|
||||
}
|
||||
|
||||
const onErr = function (err) {
|
||||
stream.destroy()
|
||||
warn('WARNING: error on reading file: %s', err)
|
||||
cb(undefined)
|
||||
}
|
||||
|
||||
stream.on('error', onErr)
|
||||
lineStream.on('data', onLine).on('end', onEnd).on('error', onErr)
|
||||
}
|
||||
|
||||
const parseLine = (module.exports.parseLine = function (line) {
|
||||
if (line.length < 11 || line.match(/^\s+#/)) {
|
||||
return null
|
||||
}
|
||||
|
||||
let curChar = ''
|
||||
let prevChar = ''
|
||||
let fieldIdx = 0
|
||||
let startIdx = 0
|
||||
let obj = {}
|
||||
let isLastField = false
|
||||
const addToObj = function (idx, i0, i1) {
|
||||
let field = line.substring(i0, i1)
|
||||
|
||||
if (!Object.hasOwnProperty.call(process.env, 'PGPASS_NO_DEESCAPE')) {
|
||||
field = field.replace(/\\([:\\])/g, '$1')
|
||||
}
|
||||
|
||||
obj[fieldNames[idx]] = field
|
||||
}
|
||||
|
||||
for (let i = 0; i < line.length - 1; i += 1) {
|
||||
curChar = line.charAt(i + 1)
|
||||
prevChar = line.charAt(i)
|
||||
|
||||
isLastField = fieldIdx == nrOfFields - 1
|
||||
|
||||
if (isLastField) {
|
||||
addToObj(fieldIdx, startIdx)
|
||||
break
|
||||
}
|
||||
|
||||
if (i >= 0 && curChar == ':' && prevChar !== '\\') {
|
||||
addToObj(fieldIdx, startIdx, i + 1)
|
||||
|
||||
startIdx = i + 2
|
||||
fieldIdx += 1
|
||||
}
|
||||
}
|
||||
|
||||
obj = Object.keys(obj).length === nrOfFields ? obj : null
|
||||
|
||||
return obj
|
||||
})
|
||||
|
||||
const isValidEntry = (module.exports.isValidEntry = function (entry) {
|
||||
const rules = {
|
||||
// host
|
||||
0: function (x) {
|
||||
return x.length > 0
|
||||
},
|
||||
// port
|
||||
1: function (x) {
|
||||
if (x === '*') {
|
||||
return true
|
||||
}
|
||||
x = Number(x)
|
||||
return isFinite(x) && x > 0 && x < 9007199254740992 && Math.floor(x) === x
|
||||
},
|
||||
// database
|
||||
2: function (x) {
|
||||
return x.length > 0
|
||||
},
|
||||
// username
|
||||
3: function (x) {
|
||||
return x.length > 0
|
||||
},
|
||||
// password
|
||||
4: function (x) {
|
||||
return x.length > 0
|
||||
},
|
||||
}
|
||||
|
||||
for (let idx = 0; idx < fieldNames.length; idx += 1) {
|
||||
const rule = rules[idx]
|
||||
const value = entry[fieldNames[idx]] || ''
|
||||
|
||||
const res = rule(value)
|
||||
if (!res) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
})
|
||||
19
packages/pg-pass/lib/index.js
Normal file
19
packages/pg-pass/lib/index.js
Normal file
@ -0,0 +1,19 @@
|
||||
'use strict'
|
||||
|
||||
const fs = require('fs'),
|
||||
helper = require('./helper.js')
|
||||
module.exports = function (connInfo, cb) {
|
||||
const file = helper.getFileName()
|
||||
|
||||
fs.stat(file, function (err, stat) {
|
||||
if (err || !helper.usePgPass(stat, file)) {
|
||||
return cb(undefined)
|
||||
}
|
||||
|
||||
const st = fs.createReadStream(file)
|
||||
|
||||
helper.getPassword(connInfo, st, cb)
|
||||
})
|
||||
}
|
||||
|
||||
module.exports.warnTo = helper.warnTo
|
||||
38
packages/pg-pass/package.json
Normal file
38
packages/pg-pass/package.json
Normal file
@ -0,0 +1,38 @@
|
||||
{
|
||||
"name": "pg-pass",
|
||||
"version": "1.0.5",
|
||||
"description": "Module for reading .pgpass",
|
||||
"main": "lib/index",
|
||||
"scripts": {
|
||||
"pretest": "chmod 600 ./test/_pgpass",
|
||||
"_test": "mocha --recursive -R list",
|
||||
"_covered_test": "nyc --reporter html --reporter text \"$npm_execpath\" run _test",
|
||||
"test": "\"$npm_execpath\" run _covered_test"
|
||||
},
|
||||
"author": "Hannes Hörl <hannes.hoerl+pgpass@snowreporter.com>",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"split2": "4.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"jshint": "2.12.0",
|
||||
"mocha": "8.2.0",
|
||||
"nyc": "15.1.0",
|
||||
"pg-escape": "0.2.0",
|
||||
"resumer": "0.0.0",
|
||||
"tmp": "0.2.1",
|
||||
"which": "2.0.2"
|
||||
},
|
||||
"keywords": [
|
||||
"postgres",
|
||||
"pg",
|
||||
"pgpass",
|
||||
"password",
|
||||
"postgresql"
|
||||
],
|
||||
"bugs": "https://github.com/hoegaarden/pgpass/issues",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/hoegaarden/pgpass.git"
|
||||
}
|
||||
}
|
||||
28
packages/pg-pass/test/#1 de-escaping.js
Normal file
28
packages/pg-pass/test/#1 de-escaping.js
Normal file
@ -0,0 +1,28 @@
|
||||
const assert = require('assert'),
|
||||
path = require('path'),
|
||||
pgPass = require(path.join('..', 'lib', 'index'))
|
||||
const conn = {
|
||||
host: 'host5',
|
||||
database: 'database5',
|
||||
user: 'dummy\\:user',
|
||||
}
|
||||
|
||||
describe('#1', function () {
|
||||
before(function () {
|
||||
process.env.PGPASS_NO_DEESCAPE = true
|
||||
process.env.PGPASSFILE = path.join(__dirname, '_pgpass')
|
||||
})
|
||||
after(function () {
|
||||
delete process.env.PGPASS_NO_DEESCAPE
|
||||
delete process.env.PGPASSFILE
|
||||
})
|
||||
|
||||
it('should not de-escape NODE_PG_NO_DESCAPE is set', function (done) {
|
||||
process.env.PGPASSFILE = path.join(__dirname, '_pgpass')
|
||||
|
||||
pgPass(conn, function (res) {
|
||||
assert.strictEqual('some:password', res)
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
19
packages/pg-pass/test/#1 escaping.js
Normal file
19
packages/pg-pass/test/#1 escaping.js
Normal file
@ -0,0 +1,19 @@
|
||||
const assert = require('assert'),
|
||||
path = require('path'),
|
||||
pgPass = require(path.join('..', 'lib', 'index'))
|
||||
const conn = {
|
||||
host: 'host4',
|
||||
port: 100,
|
||||
database: 'database4',
|
||||
user: 'user4',
|
||||
}
|
||||
|
||||
describe('#1', function () {
|
||||
it('should handle escaping right', function (done) {
|
||||
process.env.PGPASSFILE = path.join(__dirname, '_pgpass')
|
||||
pgPass(conn, function (res) {
|
||||
assert.strictEqual('some:wired:password', res)
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
34
packages/pg-pass/test/#17 unset env.js
Normal file
34
packages/pg-pass/test/#17 unset env.js
Normal file
@ -0,0 +1,34 @@
|
||||
const assert = require('assert'),
|
||||
path = require('path'),
|
||||
helper = require(path.join('..', 'lib', 'helper'))
|
||||
describe('#17 when env is empty', function () {
|
||||
const fakeEnv = {}
|
||||
|
||||
describe('getting the pgpass filename', function () {
|
||||
const checkFileName = function (expected) {
|
||||
assert.doesNotThrow(function () {
|
||||
const actual = helper.getFileName(fakeEnv)
|
||||
assert.equal(actual, expected)
|
||||
})
|
||||
}
|
||||
|
||||
describe('on unix-ish envs', function () {
|
||||
it('should not fail', function () {
|
||||
checkFileName('.pgpass')
|
||||
})
|
||||
})
|
||||
|
||||
describe('on windows', function () {
|
||||
before(function () {
|
||||
helper.isWin = true
|
||||
})
|
||||
after(function () {
|
||||
helper.isWin = process.platform === 'win32'
|
||||
})
|
||||
|
||||
it('should not fail', function () {
|
||||
checkFileName(path.join('postgresql', 'pgpass.conf'))
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
55
packages/pg-pass/test/#6 too many open files.js
Normal file
55
packages/pg-pass/test/#6 too many open files.js
Normal file
@ -0,0 +1,55 @@
|
||||
const assert = require('assert'),
|
||||
path = require('path'),
|
||||
pgPass = require(path.join('..', 'lib', 'index')),
|
||||
spawn = require('child_process').spawn,
|
||||
os = require('os')
|
||||
const conn = {
|
||||
host: 'host4',
|
||||
port: 100,
|
||||
database: 'database4',
|
||||
user: 'user4',
|
||||
}
|
||||
|
||||
let lsofBin
|
||||
try {
|
||||
lsofBin = require('which').sync('lsof')
|
||||
} catch (e) {
|
||||
if (process.env.SKIP_LSOF) {
|
||||
console.warn('WARNING: lsof not found, skipping test', __filename)
|
||||
} else {
|
||||
console.error('ERROR: lsof not found')
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
if (lsofBin) {
|
||||
describe('#6', function () {
|
||||
it('should close stream', function (done) {
|
||||
const passFile = path.join(__dirname, '_pgpass')
|
||||
process.env.PGPASSFILE = passFile
|
||||
|
||||
pgPass(conn, function (pass) {
|
||||
let out = ''
|
||||
let err = ''
|
||||
const lsofArgs = ['-w', '-Fn', '-p', process.pid]
|
||||
const lsof = spawn(lsofBin, lsofArgs)
|
||||
|
||||
lsof.stdout.on('data', function (d) {
|
||||
out = out.concat(d.toString())
|
||||
})
|
||||
lsof.stderr.on('data', function (d) {
|
||||
err = err.concat(d.toString())
|
||||
})
|
||||
lsof.on('exit', function (code) {
|
||||
const res = out.split(os.EOL).filter(function (el) {
|
||||
return el == 'n'.concat(passFile)
|
||||
})
|
||||
assert.equal(res.length, 0, 'open files found')
|
||||
assert.equal(err, '', 'printed errors')
|
||||
assert.equal(code, 0, 'exited with errors')
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
} // if lsofBin
|
||||
10
packages/pg-pass/test/_pgpass
Normal file
10
packages/pg-pass/test/_pgpass
Normal file
@ -0,0 +1,10 @@
|
||||
# comments??
|
||||
host1:1:database1:user1:pass1
|
||||
*:*:*:user2:pass2
|
||||
host3:3:database3:user3:pass3
|
||||
|
||||
host4:*:database4:user4:some\:wired\:password
|
||||
|
||||
host5:*:database5:dummy\:user:some:password
|
||||
|
||||
|
||||
256
packages/pg-pass/test/helper.js
Normal file
256
packages/pg-pass/test/helper.js
Normal file
@ -0,0 +1,256 @@
|
||||
const assert = require('assert'),
|
||||
path = require('path'),
|
||||
helper = require(path.join('..', 'lib', 'helper')),
|
||||
util = require('util'),
|
||||
Stream = require('resumer')
|
||||
describe('#warnTo()', function () {
|
||||
it('should be process.stderr by default', function () {
|
||||
const stdErr = process.stderr
|
||||
const org = helper.warnTo(stdErr)
|
||||
assert(org === stdErr)
|
||||
})
|
||||
|
||||
it('should not cause problems to give a non-stream', function () {
|
||||
const orgStream = helper.warnTo(null)
|
||||
assert(false === helper.usePgPass({ mode: 6 }))
|
||||
helper.warnTo(orgStream)
|
||||
})
|
||||
|
||||
it('should write warnings to our writable stream', function (done) {
|
||||
const stream = new Stream()
|
||||
|
||||
const orgStream = helper.warnTo(stream)
|
||||
const orgIsWin = helper.isWin
|
||||
helper.isWin = false
|
||||
|
||||
assert(process.stderr === orgStream)
|
||||
assert(false === helper.usePgPass({ mode: 6 }))
|
||||
|
||||
stream.on('data', function (d) {
|
||||
assert(0 === d.indexOf('WARNING: password file "<unkn>" is not a plain file'))
|
||||
|
||||
helper.orgisWin = orgIsWin
|
||||
helper.warnTo(orgStream)
|
||||
stream.end()
|
||||
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('#getFileName()', function () {
|
||||
it('should return the default pgpass file', function () {
|
||||
const env = {
|
||||
HOME: '/tmp',
|
||||
APPDATA: 'C:\\tmp',
|
||||
}
|
||||
assert.equal(
|
||||
helper.getFileName(env),
|
||||
process.platform === 'win32' ? 'C:\\tmp\\postgresql\\pgpass.conf' : '/tmp/.pgpass'
|
||||
)
|
||||
})
|
||||
|
||||
it('should return the the path to PGPASSFILE if set', function () {
|
||||
const env = {}
|
||||
const something = (env.PGPASSFILE = 'xxx')
|
||||
assert.equal(helper.getFileName(env), something)
|
||||
})
|
||||
})
|
||||
|
||||
describe('#isWin', function () {
|
||||
it('should represent the platform and can be changed', function () {
|
||||
const orgIsWin = helper.isWin
|
||||
const test = 'something'
|
||||
const isWin = process.platform === 'win32'
|
||||
|
||||
assert.equal(isWin, helper.isWin)
|
||||
|
||||
helper.isWin = test
|
||||
assert.equal(test, helper.isWin)
|
||||
|
||||
helper.isWin = orgIsWin
|
||||
assert.equal(isWin, helper.isWin)
|
||||
})
|
||||
})
|
||||
|
||||
describe('#usePgPass()', function () {
|
||||
// http://lxr.free-electrons.com/source/include/uapi/linux/stat.h
|
||||
const testResults = {
|
||||
'0100660': false,
|
||||
'0100606': false,
|
||||
'0100100': true,
|
||||
'0100600': true,
|
||||
'0040600': false, // is a directory
|
||||
'0060600': false, // is a blockdevice
|
||||
}
|
||||
|
||||
const org = helper.isWin // pretend we are UNIXish for permission tests
|
||||
helper.isWin = true
|
||||
Object.keys(testResults).forEach(function (octPerm) {
|
||||
const decPerm = Number(parseInt(octPerm, 8))
|
||||
const res = testResults[octPerm]
|
||||
const msg = util.format('should consider permission %s %s', octPerm, res ? 'secure' : 'not secure')
|
||||
|
||||
it(msg, function () {
|
||||
assert.equal(helper.usePgPass({ mode: decPerm }) === res, true)
|
||||
})
|
||||
})
|
||||
helper.isWin = org
|
||||
|
||||
it('should always return false if PGPASSWORD is set', function () {
|
||||
process.env.PGPASSWORD = 'some'
|
||||
assert(false === helper.usePgPass())
|
||||
delete process.env.PGPASSWORD
|
||||
})
|
||||
|
||||
it('should always return true on windows', function () {
|
||||
const org = helper.isWin
|
||||
helper.isWin = true
|
||||
assert(helper.usePgPass())
|
||||
helper.isWin = org
|
||||
})
|
||||
})
|
||||
|
||||
describe('#parseLine()', function () {
|
||||
it('should parse a simple line', function () {
|
||||
const res = helper.parseLine('host:port:dbase:user:pass')
|
||||
|
||||
assert.deepEqual(res, {
|
||||
host: 'host',
|
||||
port: 'port',
|
||||
database: 'dbase',
|
||||
user: 'user',
|
||||
password: 'pass',
|
||||
})
|
||||
})
|
||||
|
||||
it('should handle comments', function () {
|
||||
const res = helper.parseLine(' # some random comment')
|
||||
assert.equal(res, null)
|
||||
})
|
||||
|
||||
it("should handle escaped ':' and '\\' right", function () {
|
||||
/* jshint -W044 */
|
||||
const res = helper.parseLine('some\\:host:port:some\\\\database:some;user:somepass')
|
||||
/* jshint +W044 */
|
||||
assert.deepEqual(res, {
|
||||
host: 'some:host',
|
||||
port: 'port',
|
||||
database: 'some\\database',
|
||||
/* jshint -W044 */
|
||||
user: 'some;user',
|
||||
/* jshint +W044 */
|
||||
password: 'somepass',
|
||||
})
|
||||
})
|
||||
|
||||
it('should ignore too short lines', function () {
|
||||
const tests = ['::::', 'host:port', 'host:port:database', 'host:port:database:']
|
||||
|
||||
tests.forEach(function (line) {
|
||||
const res = helper.parseLine(line)
|
||||
assert.equal(null, res)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('#isValidEntry()', function () {
|
||||
it("shouldn't report valid entries", function () {
|
||||
assert(
|
||||
helper.isValidEntry({
|
||||
host: 'some:host',
|
||||
port: 100,
|
||||
database: 'some\\database',
|
||||
/* jshint -W044 */
|
||||
user: 'some;user',
|
||||
/* jshint +W044 */
|
||||
password: 'somepass',
|
||||
})
|
||||
)
|
||||
assert(
|
||||
helper.isValidEntry({
|
||||
host: '*',
|
||||
port: '*',
|
||||
database: '*',
|
||||
user: '*',
|
||||
password: 'somepass',
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it('should find invalid entries', function () {
|
||||
assert(
|
||||
!helper.isValidEntry({
|
||||
host: '',
|
||||
})
|
||||
)
|
||||
assert(
|
||||
!helper.isValidEntry({
|
||||
host: 'host',
|
||||
port: '100',
|
||||
database: 'database',
|
||||
user: 'user',
|
||||
})
|
||||
)
|
||||
assert(
|
||||
!helper.isValidEntry({
|
||||
host: 'host',
|
||||
port: -100,
|
||||
database: 'database',
|
||||
user: 'user',
|
||||
password: '232323',
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('#getPassword()', function () {
|
||||
const creds = 'host1:100:database1:user1:thepassword1' + '\n' + '*:*:database2:*:thepassword2' + '\n'
|
||||
const conn1 = {
|
||||
host: 'host1',
|
||||
port: 100,
|
||||
database: 'database1',
|
||||
user: 'user1',
|
||||
}
|
||||
const conn3 = {
|
||||
host: 'host3',
|
||||
database: 'database3',
|
||||
user: 'user3',
|
||||
}
|
||||
|
||||
it('should not get password for non-matching conn_info', function (done) {
|
||||
const st = new Stream()
|
||||
|
||||
helper.getPassword(conn3, st, function (pass) {
|
||||
assert.deepEqual(pass, undefined)
|
||||
done()
|
||||
})
|
||||
|
||||
st.write(creds)
|
||||
st.end()
|
||||
})
|
||||
|
||||
it('should get password for matching conn_info', function (done) {
|
||||
const st = new Stream()
|
||||
|
||||
helper.getPassword(conn1, st, function (pass) {
|
||||
assert.notDeepEqual(pass, undefined)
|
||||
done()
|
||||
})
|
||||
|
||||
st.write(creds)
|
||||
st.end()
|
||||
})
|
||||
|
||||
it('should ignore no password on any error', function (done) {
|
||||
const st = new Stream()
|
||||
|
||||
helper.getPassword({}, st, function (pass) {
|
||||
assert.deepEqual(pass, undefined)
|
||||
done()
|
||||
})
|
||||
|
||||
st.emit('error', new Error('just some error'))
|
||||
st.end()
|
||||
})
|
||||
})
|
||||
37
packages/pg-pass/test/index.js
Normal file
37
packages/pg-pass/test/index.js
Normal file
@ -0,0 +1,37 @@
|
||||
const assert = require('assert'),
|
||||
path = require('path'),
|
||||
pgPass = require(path.join('..', 'lib', 'index'))
|
||||
const conn = {
|
||||
host: 'host1',
|
||||
port: 100,
|
||||
database: 'somedb',
|
||||
user: 'user2',
|
||||
}
|
||||
|
||||
describe('MAIN', function () {
|
||||
it('should ignore non existent file', function (done) {
|
||||
process.env.PGPASSFILE = path.join(__dirname, '_no_such_file_')
|
||||
pgPass(conn, function (res) {
|
||||
assert(undefined === res)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should read .pgpass', function (done) {
|
||||
process.env.PGPASSFILE = path.join(__dirname, '_pgpass')
|
||||
pgPass(conn, function (res) {
|
||||
assert.strictEqual('pass2', res)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should not read .pgpass because of PGPASSWORD', function (done) {
|
||||
process.env.PGPASSFILE = path.join(__dirname, '_pgpass')
|
||||
process.env.PGPASSWORD = 'something'
|
||||
pgPass(conn, function (res) {
|
||||
assert(undefined === res)
|
||||
delete process.env.PGPASSWORD
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
170
packages/pg-pass/test/integration/#1 escaping.js
Normal file
170
packages/pg-pass/test/integration/#1 escaping.js
Normal file
@ -0,0 +1,170 @@
|
||||
const RND = Math.random()
|
||||
const USER = 'pgpass-test-some:user:'.concat(RND)
|
||||
const PASS = 'pgpass-test-some:pass:'.concat(RND)
|
||||
const POSTGRES_USER = process.env.POSTGRES_USER || 'postgres'
|
||||
const POSTGRES_PASSWORD = process.env.POSTGRES_PASSWORD || 'postgres'
|
||||
const TEST_QUERY = 'SELECT CURRENT_USER AS me'
|
||||
|
||||
const assert = require('assert')
|
||||
const spawn = require('child_process').spawn
|
||||
const fs = require('fs')
|
||||
const esc = require('pg-escape')
|
||||
const tmp = require('tmp')
|
||||
|
||||
// cleanup temp file
|
||||
tmp.setGracefulCleanup()
|
||||
|
||||
/**
|
||||
* Run connection test with
|
||||
* - natvie clien
|
||||
* - JS client
|
||||
* - psql
|
||||
*/
|
||||
if (process.env.RUN_INTEGRATION_TESTS) {
|
||||
describe('using same password file', function () {
|
||||
before(pre)
|
||||
after(delUser)
|
||||
|
||||
const config = {
|
||||
user: USER,
|
||||
database: 'postgres',
|
||||
}
|
||||
|
||||
// load the module after setting up PGPASSFILE
|
||||
const pg = require('pg')
|
||||
const pgClient = new pg.Pool(config)
|
||||
const pgNativeClient = new pg.native.Pool(config)
|
||||
|
||||
it('the JS client can connect', function (done) {
|
||||
pgClient.connect(checkConnection.bind(null, done))
|
||||
})
|
||||
|
||||
it('the native client can connect', function (done) {
|
||||
pgNativeClient.connect(checkConnection.bind(null, done))
|
||||
})
|
||||
|
||||
it('the psql client can connect', function (done) {
|
||||
runPsqlCmd(
|
||||
TEST_QUERY,
|
||||
function (err, res) {
|
||||
checkQueryRes(err, res.replace(/\n$/, ''))
|
||||
done()
|
||||
},
|
||||
USER
|
||||
)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Did running the query return an error and is the result as expected?
|
||||
*/
|
||||
function checkQueryRes(err, res) {
|
||||
assert.ifError(err)
|
||||
assert.strictEqual(USER, res)
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the connection with node-postgres
|
||||
*/
|
||||
function checkConnection(testDone, err, client, pgDone) {
|
||||
assert.ifError(err)
|
||||
|
||||
client.query(TEST_QUERY, function (err, res) {
|
||||
checkQueryRes(err, res.rows[0].me)
|
||||
pgDone()
|
||||
testDone()
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Run test setup tasks
|
||||
*/
|
||||
function pre(cb) {
|
||||
genUser(function (err) {
|
||||
if (err) {
|
||||
delUser(function () {
|
||||
throw err
|
||||
})
|
||||
} else {
|
||||
setupPassFile(cb)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape ':' and '\' before writing the password file
|
||||
*/
|
||||
function pgEsc(str) {
|
||||
return str.replace(/([:\\])/g, '\\$1')
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the temp. password file and setup the env var
|
||||
*/
|
||||
function setupPassFile(cb) {
|
||||
// 384 == 0600
|
||||
tmp.file({ mode: 384 }, function (err, path, fd) {
|
||||
if (err) {
|
||||
return cb(err)
|
||||
}
|
||||
|
||||
const str = '*:*:*:__USER__:__PASS__'.replace('__USER__', pgEsc(USER)).replace('__PASS__', pgEsc(PASS))
|
||||
const buf = Buffer.from(str)
|
||||
|
||||
fs.write(fd, buf, 0, buf.length, 0, function (err) {
|
||||
if (err) {
|
||||
return cb(err)
|
||||
}
|
||||
|
||||
process.env.PGPASSFILE = path
|
||||
cb()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* generate a new user with password using psql
|
||||
*/
|
||||
function genUser(cb) {
|
||||
const cmd = esc('CREATE USER %I WITH PASSWORD %L', USER, PASS)
|
||||
runPsqlCmd(cmd, cb, POSTGRES_USER, POSTGRES_PASSWORD)
|
||||
}
|
||||
|
||||
/**
|
||||
* delete the user using psql
|
||||
*/
|
||||
function delUser(cb) {
|
||||
const cmd = esc('DROP USER %I', USER)
|
||||
runPsqlCmd(cmd, cb, POSTGRES_USER, POSTGRES_PASSWORD)
|
||||
}
|
||||
|
||||
/**
|
||||
* run a SQL command with psql
|
||||
*/
|
||||
function runPsqlCmd(cmd, cb, user, pass) {
|
||||
const env = Object.assign({}, process.env)
|
||||
if (pass) {
|
||||
env.PGPASSWORD = pass
|
||||
}
|
||||
|
||||
// the user running the tests needs to be able to connect to
|
||||
// postgres as user 'postgres' without a password
|
||||
const psql = spawn('psql', ['-A', '-t', '-h', '127.0.0.1', '-d', 'postgres', '-U', user || 'postgres', '-c', cmd], {
|
||||
env: env,
|
||||
})
|
||||
|
||||
let out = ''
|
||||
|
||||
psql.stdout.on('data', function (data) {
|
||||
out += data.toString()
|
||||
})
|
||||
|
||||
psql.on('exit', function (code) {
|
||||
cb(code === 0 ? null : code, out)
|
||||
})
|
||||
|
||||
psql.stderr.on('data', function (err) {
|
||||
console.log('ERR:', err.toString())
|
||||
})
|
||||
}
|
||||
@ -36,7 +36,7 @@
|
||||
"pg-pool": "^3.9.6",
|
||||
"pg-protocol": "^1.9.5",
|
||||
"pg-types": "^2.1.0",
|
||||
"pgpass": "1.x"
|
||||
"pg-pass": "1.0.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@cloudflare/vitest-pool-workers": "0.8.12",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user