Skip to content

Commit

Permalink
feat: allow single tool scans (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Bouquillon authored Apr 14, 2023
1 parent 60b0d7a commit e4062e3
Show file tree
Hide file tree
Showing 9 changed files with 383 additions and 2,719 deletions.
4 changes: 4 additions & 0 deletions init/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ inputs:
description: "Single url to scan or scan all urls"
required: false
default: ""
tool:
description: "Tool to run or use all tools"
default: ""
required: false
outputs:
urls:
description: List of urls to scan as plain text
Expand Down
2,931 changes: 295 additions & 2,636 deletions init/dist/index.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

57 changes: 2 additions & 55 deletions init/dist/licenses.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,69 +10,16 @@ The above copyright notice and this permission notice shall be included in all c

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.

@actions/http-client
@vercel/ncc
MIT
Actions Http Client for Node.js

Copyright (c) GitHub, Inc.

All rights reserved.

MIT License

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.


tunnel
MIT
The MIT License (MIT)

Copyright (c) 2012 Koichi Kobayashi

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.


uuid
MIT
The MIT License (MIT)

Copyright (c) 2010-2020 Robert Kieffer and other contributors
Copyright 2018 ZEIT, Inc.

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.


yaml
ISC
Copyright 2018 Eemeli Aro <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion init/dist/sourcemap-register.js

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions init/src/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,17 @@ Array [
},
]
`;

exports[`should parse dashlord config with inputs.tool 1`] = `
Array [
Object {
"subpages": Array [
"https://voila.fr",
],
"tools": Object {
"lighthouse": true,
},
"url": "https://voila.fr",
},
]
`;
58 changes: 38 additions & 20 deletions init/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ const YAML = require("yaml");
const getDashlordConfig = () => {
let dashlordConfig;
if (fs.existsSync("./dashlord.yml")) {
core.info('----')
core.info("----");
core.info(`load dashlord.yml`);
core.info('----')
core.info("----");
const content = fs.readFileSync("./dashlord.yml", "utf8").toString();
core.info(content)
core.info(content);
dashlordConfig = YAML.parse(content);
} else if (fs.existsSync("./dashlord.yaml")) {
core.info(`load dashlord.yaml`);
Expand All @@ -19,24 +19,26 @@ const getDashlordConfig = () => {
throw new Error("Cannot load dashlord.yml");
}

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

const getSiteTools = (site) => {
core.info(`site=${JSON.stringify(site)}`)
core.info(`site.tools=${JSON.stringify(site.tools)}`)
core.info(`site=${JSON.stringify(site)}`);
core.info(`site.tools=${JSON.stringify(site.tools)}`);
let dashlordConfig = getDashlordConfig();
if (!dashlordConfig.tools) {
return {}
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;
site.tools[tool] === undefined
? dashlordConfig.tools[tool] === false
: site.tools[tool] === false;
return {
...siteTools,
[tool]: !isToolDisabled,
Expand All @@ -45,11 +47,15 @@ const getSiteTools = (site) => {
};

const getSiteSubpages = (site) => {
core.info(`site=${JSON.stringify(site)}`)
core.info(`site.pages=${JSON.stringify(site.pages)}`)
const subpages = [site.url.replace(/\/$/,"")];
core.info(`site=${JSON.stringify(site)}`);
core.info(`site.pages=${JSON.stringify(site.pages)}`);
const subpages = [site.url.replace(/\/$/, "")];
if (site.pages !== undefined) {
subpages.push(...site.pages.map((page) => [site.url.replace(/\/$/,""), page.replace(/^\//,"")].join("/")));
subpages.push(
...site.pages.map((page) =>
[site.url.replace(/\/$/, ""), page.replace(/^\//, "")].join("/")
)
);
}
return subpages;
};
Expand All @@ -62,16 +68,24 @@ const getOutputs = () => {
.split(",")
.map((s) => s.trim())
.filter(Boolean);
const toolInput = core.getInput("tool") && core.getInput("tool").trim();

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

const isValid = (u) => u.url.match(/^https?:\/\//);
let dashlordConfig = getDashlordConfig();
let baseSites = dashlordConfig.urls;

if (!baseSites && urlsInput) baseSites = urlsInput.map((url) => ({ url }));

core.info(`baseSites : ${baseSites}`);
if (
toolInput &&
toolInput !== "all" &&
!Object.keys(dashlordConfig.tools).includes(toolInput)
) {
throw new Error(`Tool not found : ${toolInput}`);
}

const sites = baseSites
.filter(isValid)
Expand All @@ -82,14 +96,18 @@ const getOutputs = () => {
)
.map((site) => ({
...site,
tools: getSiteTools(site),
subpages: getSiteSubpages(site)
tools:
toolInput && toolInput !== "all"
? { [toolInput]: true }
: getSiteTools(site),
subpages: getSiteSubpages(site),
}));

const urls = sites.map((u) => u.url).join("\n");

core.info(`urls :${urls}`);
core.info(`sites :${JSON.stringify(sites)}`);
core.info(`config :${JSON.stringify(dashlordConfig)}`);
core.info(`sites: ${JSON.stringify(sites)}`);
core.info(`config: ${JSON.stringify(dashlordConfig)}`);

return { urls, sites, config: dashlordConfig };
};
Expand Down
17 changes: 14 additions & 3 deletions init/src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,13 @@ describe("should parse dashlord config", () => {
},
});
core.info(`subpages=${JSON.stringify(subpages)}`);
expect(subpages).toEqual(["https://chez.com", "https://chez.com/login", "https://chez.com/profile"]);
expect(subpages).toEqual([
"https://chez.com",
"https://chez.com/login",
"https://chez.com/profile",
]);
});



test("and getSiteSubpages https://voila.fr match", async () => {
inputs.url = "https://voila.fr";
fs.existsSync.mockReturnValue(true);
Expand All @@ -124,4 +126,13 @@ describe("should parse dashlord config", () => {
core.info(`subpages=${JSON.stringify(subpages)}`);
expect(subpages).toEqual(["https://voila.fr"]);
});

test("with inputs.tool", async () => {
inputs.url = "https://voila.fr";
inputs.tool = "lighthouse";
fs.existsSync.mockReturnValue(true);
fs.readFileSync.mockReturnValue(sampleConfig);
const outputs = getOutputs();
expect(outputs.sites).toMatchSnapshot();
});
});
17 changes: 14 additions & 3 deletions save/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ inputs:
url:
description: URL to save data for
required: true

cleanup:
description: Cleanup previous data
required: false
default: "true"
#
# this actions copy scanners results to the dashlord repository for versionning
#
Expand All @@ -16,6 +19,7 @@ runs:
- shell: bash
run: |
URL=${{ inputs.url }}
CLEANUP=${{ inputs.cleanup }}
HOSTNAME=$(echo "${{ inputs.url }}" | sed -e 's/[^/]*\/\/\([^@]*@\)\?\([^:/]*\).*/\2/')
DASHLORD_REPO_PATH=${{ github.workspace }};
# store results in a folder with then base64 encoded url
Expand All @@ -27,14 +31,21 @@ runs:
echo "HOSTNAME: $HOSTNAME"
echo "DASHLORD_REPO_PATH: $DASHLORD_REPO_PATH"
echo "OUT_PATH: $OUT_PATH"
echo "CLEANUP: $CLEANUP"
cd $DASHLORD_REPO_PATH
mkdir -p $OUT_PATH || true
# cleanup previous scans results
echo "Cleanup $OUT_PATH"
rm -rf $OUT_PATH/*
if [[ "$CLEANUP" = "true" ]]
then
echo "Cleanup $OUT_PATH"
rm -rf $OUT_PATH/*
else
# dont cleanup, for example when a single tool is run
echo "Skip cleanup $OUT_PATH"
fi
ls -la scans
Expand Down

0 comments on commit e4062e3

Please sign in to comment.