Skip to content

Commit

Permalink
Seceng 260/sync with upstream (#36)
Browse files Browse the repository at this point in the history
* add a github action to sync upstream branch to staging (#34)

* add a github action to sync upstream branch to staging

* remove trailing space from github action

* fix yamllint errors

* fix yaml lint issues

* relax yamllint config rules

* fix yamllint rules config

* lint App.tsx

* restore hopper config

* update yamllint rules config

* add selenium docker image to test yopass secret retrieval (#35)

* add selenium docker image to test yopass secret retrieval

* fix typo in circle config

* fix circle config

* update docker-compose config for yopass container

* add missing checkout step to docker compose task

* add setup_remote_docker config for circleci

* increase wait time and echo selenium result

* use f-string to populate yopass test url in selenium test

* debug docker compose ICC issue

* attempt to connect to yopass container via ip

* take out network debug lines from circleci config

* remove custom bridged network to debug

* remove old network config from docker compose

* update url for selenium test

* updated docker-compose config

* re-add internal bridged network to docker

* include no cache arg to docker compose

* update circleci config and remove comment from selenium script

* add newline to end of docker compose file

* add newline to end of docker compose file

* replace sleep with wait argument for docker compose and tear down containers when done

* update docker to wait for healthy containers and re-added sleep and updated github action to raise a PR on sync

* remove trailing space for github action

* revert file perms for hopper config
  • Loading branch information
roo-ahine authored Sep 30, 2024
1 parent e48b05b commit fa496e3
Show file tree
Hide file tree
Showing 7 changed files with 217 additions and 23 deletions.
41 changes: 37 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,30 @@ build_docker_image: &build_docker_image
paths:
- '*.tar'

test_yopass_secret: &test_yopass_secret
executor: docker-container
steps:
- attach_workspace:
at: /tmp/workspace
- setup_remote_docker:
docker_layer_caching: true
- checkout
- run:
name: Add and retrieve test secret
command: |
docker compose build --no-cache
docker compose up -d --wait
sleep 5
yopass_result=$(docker compose logs selenium_browser | cut -d '|' -f2 | xargs 2>&1)
echo $yopass_result
if [ "$yopass_result" = "PASS" ]; then
echo "Secret successfully generated and retrieved from Yopass"
else
echo "Secret generation and retrieval failed!"
exit 1
fi
docker compose down
push_image_to_ecr: &push_image_to_ecr
executor: docker-container
steps:
Expand All @@ -63,20 +87,25 @@ filter_master_branch: &filter_master_branch
filters:
branches:
only:
- master
- master

filter_staging_branch: &filter_staging_branch
filters:
branches:
only:
- staging
- staging

jobs:
build_docker_image:
executor: docker-container
resource_class: small
<<: *build_docker_image

add_and_retrieve_test_secret:
executor: docker-container
resource_class: small
<<: *test_yopass_secret

push_ecr_image_to_staging:
executor: docker-container
resource_class: small
Expand All @@ -97,13 +126,17 @@ workflows:
jobs:
- build_docker_image:
<<: *global_context
- add_and_retrieve_test_secret:
<<: *global_context
requires:
- build_docker_image
- push_ecr_image_to_staging:
<<: *global_context
<<: *filter_staging_branch
requires:
- build_docker_image
- add_and_retrieve_test_secret
- push_ecr_image_to_production:
<<: *global_context
<<: *filter_master_branch
requires:
- build_docker_image
- add_and_retrieve_test_secret
19 changes: 1 addition & 18 deletions .github/linters/.yaml-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,10 @@ rules:
level: warning
commas:
level: warning
comments:
level: warning
require-starting-space: true
min-spaces-from-content: 1
comments-indentation: disable
document-start: disable
document-end: disable
empty-lines:
level: warning
empty-values:
level: warning
hyphens:
max-spaces-after: 1
level: warning
indentation:
spaces: 2
indent-sequences: consistent
check-multi-line-strings: true
key-duplicates: enable
key-ordering: disable
line-length:
max: 160
level: warning
Expand All @@ -48,5 +32,4 @@ rules:
octal-values: disable
quoted-strings: disable
trailing-spaces: enable
truthy:
level: warning
indentation: disable
55 changes: 55 additions & 0 deletions .github/workflows/sync-repo-with-upstream.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Sync Repo with Upstream and raise PR

on:
schedule:
- cron: '35 9 * * *' # Runs daily at 9:35 AM UTC
workflow_dispatch: # Allows manual triggering

jobs:
sync:
runs-on: ubuntu-latest

steps:
- name: Checkout the repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Git
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
- name: Add upstream remote https://github.com/jhaals/yopass.git
run: git remote add upstream

- name: Fetch upstream changes
run: git fetch upstream

- name: Checkout new branch
id: checkout-new-branch
run: |
BRANCH_NAME="sync-upstream-$(date +%s)"
echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_ENV
git checkout -b $BRANCH_NAME
- name: Merge upstream changes excluding Dockerfile
run: |
git merge upstream/main --no-commit --no-ff --allow-unrelated-histories || true
git reset HEAD Dockerfile
git checkout -- Dockerfile
git add -A
- name: Push changes to the new branch
run: |
git push origin $BRANCH_NAME
- name: Create Pull Request
uses: peter-evans/create-pull-request@v7
with:
commit-message: 'Sync with upstream'
branch: $BRANCH_NAME
title: 'Sync with upstream Yopass repository'
body: |
This PR keeps the forked repository in sync with the upstream Yopass repository
base: staging
34 changes: 34 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
networks:
internal:
driver: bridge

services:
redis:
image: redis:latest
networks:
- internal
ports:
- "6379:6379"

yopass:
build:
dockerfile: Dockerfile
ports:
- "80:80"
depends_on:
- redis
networks:
- internal
environment:
- REDIS_CACHE_URL=redis://redis:6379

selenium_browser:
build:
context: ./selenium_browser
dockerfile: Dockerfile
container_name: selenium_browser
depends_on:
- redis
- yopass
networks:
- internal
27 changes: 27 additions & 0 deletions selenium_browser/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM python:3.9-slim

RUN apt-get update -qq -y && \
apt-get install -y \
libasound2 \
libatk-bridge2.0-0 \
libgtk-4-1 \
libnss3 \
xdg-utils \
unzip \
vim \
wget && \
wget -q -O chrome-linux64.zip https://bit.ly/chrome-linux64-121-0-6167-85 && \
unzip chrome-linux64.zip && \
rm chrome-linux64.zip && \
mv chrome-linux64 /opt/chrome/ && \
ln -s /opt/chrome/chrome /usr/local/bin/ && \
wget -q -O chromedriver-linux64.zip https://bit.ly/chromedriver-linux64-121-0-6167-85 && \
unzip -j chromedriver-linux64.zip chromedriver-linux64/chromedriver && \
rm chromedriver-linux64.zip && \
mv chromedriver /usr/local/bin/

RUN pip install selenium

COPY yopass_secret_test.py .

CMD ["python", "yopass_secret_test.py"]
62 changes: 62 additions & 0 deletions selenium_browser/yopass_secret_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Automate generating and retrieving a test secret from Yopass
# Simulates adding a secret in the form field, submitting the Encrypt Message button
# Retrieve secret from Redis cache by browsing to one-time generated URL and compare input and output match

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

# Set up Chrome options
chrome_options = Options()
chrome_options.add_argument("start-maximized") # Run headless Chrome
chrome_options.add_argument("disable-infobars") # Run headless Chrome
chrome_options.add_argument("--disable-exensions") # Run headless Chrome
chrome_options.add_argument("--disable-dev-shm-usage") # Run headless Chrome
chrome_options.add_argument("--no-sandbox") # Run headless Chrome
chrome_options.add_argument("--headless") # Run headless Chrome

# Set up the ChromeDriver service
service = Service('/usr/local/bin/chromedriver')

# Initialize the WebDriver
driver = webdriver.Chrome(service=service, options=chrome_options)

# Set the URL
url = 'http://yopass'

# Set test secret
test_secret = 'this is a Selenium test secret'

# Open the URL
driver.get(url)
driver.implicitly_wait(30)

# Submit the test secret
testSecret = driver.find_element("name", "secret");
testSecret.send_keys(test_secret);
button = driver.find_element("xpath", "//button[span[text()='Encrypt Message']]")
button.click()

# Get the response text
wait = WebDriverWait(driver, 10)
link_element = wait.until(EC.presence_of_element_located((By.ID, 'root')))
link_element = driver.find_element(By.XPATH, f'//td[contains(text(), "{url}/#/s/")]')
complete_url = link_element.text

# Retrieve the test secret
driver.get(complete_url)
driver.implicitly_wait(60)

secret_element = wait.until(EC.presence_of_element_located((By.ID, 'pre')))

if secret_element.text == test_secret:
print("PASS")
else:
print("FAIL")

# Close the WebDriver
driver.quit()
2 changes: 1 addition & 1 deletion website/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ const App = () => {
);
};

export default App;
export default App;

0 comments on commit fa496e3

Please sign in to comment.