Skip to content

Commit

Permalink
Merge pull request #1209 from tubone24/fix_ad
Browse files Browse the repository at this point in the history
Fix ad
  • Loading branch information
tubone24 authored Jan 8, 2023
2 parents f318b9a + 94419c4 commit 84472f8
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 9 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ functions/src/complaints*
storybook-static/*
static/adstir.js
coverage/*
scripts/uploadScreenShot.ts
35 changes: 35 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -297,3 +297,38 @@ jobs:
publish_dir: ./public
destination_dir: lh
keep_files: true

webscreenshot:
needs:
- build
strategy:
matrix:
os: [ubuntu-latest]
width: [1920, 1200, 768, 400]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: denoland/setup-deno@v1
with:
deno-version: 'v1.x'
- name: install noto font
run: sudo apt install fonts-noto
- name: Capture Webpage Screenshot
uses: swinton/[email protected]
with:
source: "https://blog.tubone-project24.xyz"
destination: screenshot-${{ matrix.os }}-${{ matrix.width }}.png
width: ${{ matrix.width }}
delay: 10
- uses: actions/download-artifact@v3
with:
name: screenshot-${{ matrix.os }}-${{ matrix.width }}
- name: PR Comments
env:
FILE_PATH: screenshot-${{ matrix.os }}-${{ matrix.width }}.png
FILE_NAME: screenshot-${{ matrix.os }}-${{ matrix.width }}.png
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPOSITORY: "tubone24/blog"
GITHUB_PULL_REQUEST_NUMBER: ${{ steps.get-pr-num.outputs.prnum }}
BRANCH_NAME: "master"
run: deno run --allow-env --allow-read --allow-net scripts/uploadScreenShot.ts
31 changes: 25 additions & 6 deletions .github/workflows/previewDeploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -487,26 +487,45 @@ jobs:
run:
gh pr comment -F ./comments.txt "${URL}"


webscreenshot:
needs:
- build
- check-skip-flags
strategy:
matrix:
os: [ubuntu-latest]
width: [1200, 992, 768, 600]
width: [1920, 1200, 768, 400]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: denoland/setup-deno@v1
with:
deno-version: 'v1.x'
- name: install noto font
run: sudo apt install fonts-noto
- name: Capture Webpage Screenshot
if: ${{ !contains(needs.check-skip-flags.outputs.head-commit-message, '[skip netlify]') }}
uses: swinton/[email protected].0
uses: swinton/[email protected].2
with:
source: ${{ needs.build.outputs.draftUrl }}
destination: screenshot-${{ matrix.os }}-${{ matrix.width }}.png
width: ${{ matrix.width }}
- uses: actions/upload-artifact@v3
delay: 10
- uses: actions/download-artifact@v3
with:
name: screenshot-${{ matrix.os }}-${{ matrix.width }}.png
path: screenshot-${{ matrix.os }}-${{ matrix.width }}.png
name: screenshot-${{ matrix.os }}-${{ matrix.width }}
- name: ls
run: ls -la
- name: Get PR Number
id: get-pr-num
run: echo "prnum=$(echo $GITHUB_REF | sed -e 's/[^0-9]//g')" >> $GITHUB_OUTPUT
- name: PR Comments
env:
FILE_PATH: screenshot-${{ matrix.os }}-${{ matrix.width }}.png
FILE_NAME: screenshot-${{ matrix.os }}-${{ steps.get-pr-num.outputs.prnum }}-${{ github.head_ref }}-${{ matrix.width }}.png
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPOSITORY: "tubone24/blog"
GITHUB_PULL_REQUEST_NUMBER: ${{ steps.get-pr-num.outputs.prnum }}
BRANCH_NAME: "screenshot"
run: deno run --allow-env --allow-read --allow-net scripts/uploadScreenShot.ts

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ test/memlab/data
# OWASPZAP
owasp/zap/*.key
owasp/zap/*.cer
owasp/zap/zapHome/
owasp/zap/zapHome/
4 changes: 2 additions & 2 deletions functions/src/csp-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ const transaction = Sentry.startTransaction({
exports.handler = (event, context) => {
console.log(event, context);
if (!event.body) {
Sentry.captureException(new Error(event));
Sentry.captureException(new Error(JSON.stringify(event)));
transaction.finish();
return {
statusCode: 400,
body: JSON.stringify({ status: "Bad Request" }),
};
}
const body = JSON.parse(event.body);
Sentry.captureException(new Error(body));
Sentry.captureException(new Error(JSON.stringify(body)));
transaction.finish();
return {
statusCode: 200,
Expand Down
22 changes: 22 additions & 0 deletions owasp/zap/alertFilter.conf
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,25 @@ globalalertfilter.filters.filter(7).attackregex=false
globalalertfilter.filters.filter(7).evidence=
globalalertfilter.filters.filter(7).evidenceregex=false
globalalertfilter.filters.filter(7).enabled=true
globalalertfilter.filters.filter(8).ruleid=90022
globalalertfilter.filters.filter(8).newrisk=-1
globalalertfilter.filters.filter(8).url=http://web:9000/page-data/2022/01/03/owaspzap/page-data.json
globalalertfilter.filters.filter(8).urlregex=false
globalalertfilter.filters.filter(8).param=
globalalertfilter.filters.filter(8).paramregex=false
globalalertfilter.filters.filter(8).attack=
globalalertfilter.filters.filter(8).attackregex=false
globalalertfilter.filters.filter(8).evidence=Internal Server Error
globalalertfilter.filters.filter(8).evidenceregex=false
globalalertfilter.filters.filter(8).enabled=true
globalalertfilter.filters.filter(9).ruleid=90022
globalalertfilter.filters.filter(9).newrisk=-1
globalalertfilter.filters.filter(9).url=http://web:9000/page-data/index/page-data.json
globalalertfilter.filters.filter(9).urlregex=false
globalalertfilter.filters.filter(9).param=
globalalertfilter.filters.filter(9).paramregex=false
globalalertfilter.filters.filter(9).attack=
globalalertfilter.filters.filter(9).attackregex=false
globalalertfilter.filters.filter(9).evidence=Internal Server Error
globalalertfilter.filters.filter(9).evidenceregex=false
globalalertfilter.filters.filter(9).enabled=true
43 changes: 43 additions & 0 deletions scripts/uploadScreenShot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { encode } from "https://deno.land/std/encoding/base64.ts";

const GITHUB_API_URL = "https://api.github.com";
const AUTHOR_NAME = "github-actions[bot]";
const AUTHOR_EMAIL = "github-actions[bot]@users.noreply.github.com";
const filePath = Deno.env.get("FILE_PATH") as string;
const fileName = Deno.env.get("FILE_NAME") as string;
const gitHubToken = Deno.env.get("GITHUB_TOKEN") as string;
const gitHubRepo = Deno.env.get("GITHUB_REPOSITORY") as string;
const prNumber = Deno.env.get("GITHUB_PULL_REQUEST_NUMBER") as string;
const branchName = Deno.env.get("BRANCH_NAME") as string;

const readImageData = await Deno.readFile(filePath);
const encodedData = encode(readImageData);

const gitHubPayload = {
message: `[file upload] Added file for PR #${prNumber}`,
content: encodedData.replace(new RegExp("data.*base64,"), ""),
branch: branchName,
author: {
name: AUTHOR_NAME,
email: AUTHOR_EMAIL,
},
committer: {
name: AUTHOR_NAME,
email: AUTHOR_EMAIL,
},
};

const gitHubHeaders = {
Accept: "application/vnd.github.v3+json",
Authorization: `Bearer ${gitHubToken}`,
};

const gitHubUploadurl = `${GITHUB_API_URL}/repos/${gitHubRepo}/contents/docs/screenshot/${fileName}`;

const gitHubRes = await fetch(gitHubUploadurl, {
method: "PUT",
headers: gitHubHeaders,
body: JSON.stringify(gitHubPayload),
});

console.log(gitHubRes);

0 comments on commit 84472f8

Please sign in to comment.