Skip to content

Commit

Permalink
fix: fixes site tools ignored (#60)
Browse files Browse the repository at this point in the history
* fix: some tools enabled are ignored
Fixes #58

* fix: ci actions tests

* fix: ci init action

* fix: 404 doublon types

Co-authored-by: Julien Bouquillon <julien.bouquillon@sg.social.gouv.fr>

Co-authored-by: Julien Bouquillon <julien.bouquillon@sg.social.gouv.fr>
  • Loading branch information
tristanrobert and Julien Bouquillon authored Sep 14, 2021
1 parent 66c50d4 commit e89872c
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 85 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/init-matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
uses: "./init"
- id: test
run: |
EXPECTED='[{url:https://www.free.fr,title:Free,repositories:[iliad/free-ui,iliad/free-api],tools:{screenshot:true,nmap:true,zaproxy:true,wappalyzer:true,http:true,testssl:true,lighthouse:true,thirdparties:true,nuclei:true,updownio:true,dependabot:true,codescan:true,stats:true}},{url:http://chez.com,repositories:[chez/chez-ui,chez/chez-api],tools:{screenshot:false,nmap:true,zaproxy:true,wappalyzer:true,http:true,testssl:true,lighthouse:true,thirdparties:true,nuclei:true,updownio:false,dependabot:true,codescan:true,stats:false}},{url:https://voila.fr,tools:{screenshot:true,nmap:true,zaproxy:true,wappalyzer:true,http:true,testssl:true,lighthouse:true,thirdparties:true,nuclei:true,updownio:true,dependabot:true,codescan:true,stats:true}}]'
EXPECTED="[{"url":"https://www.free.fr","title":"Free","repositories":["iliad/free-ui","iliad/free-api"],"tools":{"screenshot":true,"nmap":true,"zap":true,"wappalyzer":true,"http":true,"testssl":true,"lighthouse":true,"thirdparties":true,"nuclei":true,"updownio":true,"dependabot":true,"codescan":true,"stats":true}},{"url":"http://chez.com","repositories":["chez/chez-ui","chez/chez-api"],"tools":{"screenshot":false,"nmap":true,"zap":true,"wappalyzer":true,"http":true,"testssl":true,"lighthouse":true,"thirdparties":true,"nuclei":true,"updownio":false,"dependabot":true,"codescan":true,"stats":false}},{"url":"https://voila.fr","tools":{"screenshot":true,"nmap":true,"zap":true,"wappalyzer":true,"http":true,"testssl":true,"lighthouse":true,"thirdparties":true,"nuclei":true,"updownio":true,"dependabot":true,"codescan":true,"stats":true}}]"
RESULT="${{ steps.init.outputs.sites }}"
echo "RESULT=$RESULT"
[[ "$EXPECTED" == "$RESULT" ]]
Expand Down Expand Up @@ -65,7 +65,7 @@ jobs:
url: "https://www.free.fr,https://voila.fr"
- id: test
run: |
EXPECTED='[{url:https://www.free.fr,title:Free,repositories:[iliad/free-ui,iliad/free-api],tools:{screenshot:true,nmap:true,zaproxy:true,wappalyzer:true,http:true,testssl:true,lighthouse:true,thirdparties:true,nuclei:true,updownio:true,dependabot:true,codescan:true,stats:true}},{url:https://voila.fr,tools:{screenshot:true,nmap:true,zaproxy:true,wappalyzer:true,http:true,testssl:true,lighthouse:true,thirdparties:true,nuclei:true,updownio:true,dependabot:true,codescan:true,stats:true}}]'
EXPECTED="[{"url":"https://www.free.fr","title":"Free","repositories":["iliad/free-ui","iliad/free-api"],"tools":{"screenshot":true,"nmap":true,"zap":true,"wappalyzer":true,"http":true,"testssl":true,"lighthouse":true,"thirdparties":true,"nuclei":true,"updownio":true,"dependabot":true,"codescan":true,"stats":true}},{"url":"https://voila.fr","tools":{"screenshot":true,"nmap":true,"zap":true,"wappalyzer":true,"http":true,"testssl":true,"lighthouse":true,"thirdparties":true,"nuclei":true,"updownio":true,"dependabot":true,"codescan":true,"stats":true}}]"
RESULT="${{ steps.init.outputs.sites }}"
echo "RESULT=$RESULT"
[[ "$EXPECTED" == "$RESULT" ]]
Expand Down
2 changes: 1 addition & 1 deletion dashlord.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ footer: Powered by BetaGouv
tools:
screenshot: true
nmap: true
zaproxy: true
zap: true
wappalyzer: true
http: true
testssl: true
Expand Down
5 changes: 3 additions & 2 deletions init/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,17 @@ title: Test 1
tools:
screenshot: true
nmap: true
zaproxy: true
zap: true
wappalyzer: true
httpobs: true
http: true
testssl: true
lighthouse: true
thirdparties: true
nuclei: false
updownio: true
dependabot: true
codescan: true
404: true
urls:
- url: https://www.free.fr
title: Free
Expand Down
8 changes: 5 additions & 3 deletions init/dashlord.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ title: Test 1
tools:
screenshot: true
nmap: true
zaproxy: true
zap: true
wappalyzer: true
httpobs: true
testssl: true
http: true
testssl: false
lighthouse: true
thirdparties: true
nuclei: false
updownio: true
dependabot: true
codescan: true
stats: true
404: true
urls:
- url: https://www.free.fr
title: Free
Expand All @@ -28,4 +29,5 @@ urls:
screenshot: false
updownio: false
stats: false
testssl: true
- url: https://voila.fr
65 changes: 36 additions & 29 deletions init/dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion init/dist/index.js.map

Large diffs are not rendered by default.

38 changes: 22 additions & 16 deletions init/src/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@ Array [
],
"title": "Free",
"tools": Object {
"404": true,
"codescan": true,
"dependabot": true,
"httpobs": true,
"http": true,
"lighthouse": true,
"nmap": true,
"nuclei": false,
"screenshot": true,
"stats": true,
"testssl": true,
"testssl": false,
"thirdparties": true,
"updownio": true,
"wappalyzer": true,
"zaproxy": true,
"zap": true,
},
"url": "https://www.free.fr",
},
Expand All @@ -31,9 +32,10 @@ Array [
"chez/chez-api",
],
"tools": Object {
"404": true,
"codescan": true,
"dependabot": true,
"httpobs": true,
"http": true,
"lighthouse": true,
"nmap": true,
"nuclei": false,
Expand All @@ -43,7 +45,7 @@ Array [
"thirdparties": true,
"updownio": false,
"wappalyzer": true,
"zaproxy": true,
"zap": true,
},
"url": "http://chez.com",
},
Expand All @@ -59,19 +61,20 @@ Array [
],
"title": "Free",
"tools": Object {
"404": true,
"codescan": true,
"dependabot": true,
"httpobs": true,
"http": true,
"lighthouse": true,
"nmap": true,
"nuclei": false,
"screenshot": true,
"stats": true,
"testssl": true,
"testssl": false,
"thirdparties": true,
"updownio": true,
"wappalyzer": true,
"zaproxy": true,
"zap": true,
},
"url": "https://www.free.fr",
},
Expand All @@ -81,9 +84,10 @@ Array [
"chez/chez-api",
],
"tools": Object {
"404": true,
"codescan": true,
"dependabot": true,
"httpobs": true,
"http": true,
"lighthouse": true,
"nmap": true,
"nuclei": false,
Expand All @@ -93,25 +97,26 @@ Array [
"thirdparties": true,
"updownio": false,
"wappalyzer": true,
"zaproxy": true,
"zap": true,
},
"url": "http://chez.com",
},
Object {
"tools": Object {
"404": true,
"codescan": true,
"dependabot": true,
"httpobs": true,
"http": true,
"lighthouse": true,
"nmap": true,
"nuclei": false,
"screenshot": true,
"stats": true,
"testssl": true,
"testssl": false,
"thirdparties": true,
"updownio": true,
"wappalyzer": true,
"zaproxy": true,
"zap": true,
},
"url": "https://voila.fr",
},
Expand All @@ -129,19 +134,20 @@ Array [
],
"title": "Free",
"tools": Object {
"404": true,
"codescan": true,
"dependabot": true,
"httpobs": true,
"http": true,
"lighthouse": true,
"nmap": true,
"nuclei": false,
"screenshot": true,
"stats": true,
"testssl": true,
"testssl": false,
"thirdparties": true,
"updownio": true,
"wappalyzer": true,
"zaproxy": true,
"zap": true,
},
"url": "https://www.free.fr",
},
Expand Down
65 changes: 36 additions & 29 deletions init/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,7 @@ const fs = require("fs");
const core = require("@actions/core");
const YAML = require("yaml");

const getOutputs = () => {
const urlsInput =
core.getInput("url") &&
core
.getInput("url")
.split(",")
.map((s) => s.trim())
.filter(Boolean);

core.info(`urlsInput :${urlsInput}`);

const getDashlordConfig = () => {
let dashlordConfig;
if (fs.existsSync("./dashlord.yml")) {
core.info('----')
Expand All @@ -30,26 +20,43 @@ const getOutputs = () => {
}

core.info(JSON.stringify(dashlordConfig))
return dashlordConfig
}

const getSiteTools = (site) => {
core.info(`site=${JSON.stringify(site)}`)
core.info(`site.tools=${JSON.stringify(site.tools)}`)
let dashlordConfig = getDashlordConfig();
if (!dashlordConfig.tools) {
return {}
}
if (!site.tools) {
return dashlordConfig.tools;
}
return Object.keys(dashlordConfig.tools).reduce((siteTools, tool) => {
// tool status can be set at global or site level, if defined at site level and global then site level wins.
const isToolDisabled =
site.tools[tool] === undefined ? dashlordConfig.tools[tool] === false : site.tools[tool] === false;
return {
...siteTools,
[tool]: !isToolDisabled,
};
}, {});
};

const getSiteTools = (site) => {
if (!dashlordConfig.tools) {
return {}
}
if (!site.tools) {
return dashlordConfig.tools;
}
return Object.keys(dashlordConfig.tools).reduce((siteTools, tool) => {
// tool can be disabled at global or site level
const isToolDisabled =
dashlordConfig.tools[tool] === false || site.tools[tool] === false;
return {
...siteTools,
[tool]: !isToolDisabled,
};
}, {});
};
const getOutputs = () => {
const urlsInput =
core.getInput("url") &&
core
.getInput("url")
.split(",")
.map((s) => s.trim())
.filter(Boolean);

core.info(`urlsInput :${urlsInput}`);

const isValid = (u) => u.url.match(/^https?:\/\//);
let dashlordConfig = getDashlordConfig();
const sites = dashlordConfig.urls
.filter(isValid)
.filter((url) =>
Expand Down Expand Up @@ -83,4 +90,4 @@ if (require.main === module) {
run();
}

module.exports = { run, getOutputs };
module.exports = { run, getOutputs, getSiteTools };
Loading

0 comments on commit e89872c

Please sign in to comment.