Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: e2e tests

on: [pull_request]

jobs:
unittest:
runs-on: ubuntu-latest
env:
YETI_ENDPOINT: 'http://localhost:80'
strategy:
matrix:
os: [ubuntu-latest]
python-version: ["3.10"]
steps:
- uses: actions/checkout@v4

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y python3-pip git
sudo pip3 install poetry

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: poetry

- name: Install a Yeti prod deployment
run: |
git clone https://github.com/yeti-platform/yeti-docker
cd yeti-docker/prod
./init.sh
sleep 10

- name: Create test Yeti user
run: |
cd yeti-docker/prod
echo "YETI_API_KEY=$(docker compose run --rm api create-user test test --admin | awk -F'test:' '{print $2}')" >> $GITHUB_ENV

- name: Install Python dependencies
run: poetry install --no-root

- name: e2e testing
run: |
YETI_API_KEY=$YETI_API_KEY poetry run python -m unittest tests/e2e.py
2 changes: 1 addition & 1 deletion .github/workflows/unittests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ jobs:
run: poetry install --no-root
- name: Test with unittest
run: |
poetry run python -m unittest discover -s tests/ -p '*.py'
poetry run python -m unittest tests/api.py
65 changes: 65 additions & 0 deletions tests/e2e.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import os
import time
import unittest
from unittest.mock import MagicMock, patch

import requests

from yeti import errors
from yeti.api import YetiApi


class YetiEndToEndTest(unittest.TestCase):
def setUp(self):
self.api = YetiApi(os.getenv("YETI_ENDPOINT"))

def test_auth_api_key(self):
self.api.auth_api_key(os.getenv("YETI_API_KEY"))
self.api.search_indicators(name="test")

def test_no_auth(self):
with self.assertRaises(errors.YetiAuthError) as error:
self.api.search_indicators(name="test")
self.assertIn(
"401 Client Error: Unauthorized for url: ",
str(error.exception),
)

def test_new_indicator(self):
self.api.auth_api_key(os.getenv("YETI_API_KEY"))
indicator = self.api.new_indicator(
{
"name": "test",
"type": "regex",
"description": "test",
"pattern": "test[0-9]",
"diamond": "victim",
}
)
self.assertEqual(indicator["name"], "test")
self.assertRegex(indicator["id"], r"[0-9]+")

def test_auth_refresh(self):
self.api.auth_api_key(os.getenv("YETI_API_KEY"))
self.api.search_indicators(name="test")

time.sleep(3)

self.api.search_indicators(name="test")

def test_search_indicators(self):
self.api.auth_api_key(os.getenv("YETI_API_KEY"))
self.api.auth_api_key(os.getenv("YETI_API_KEY"))
indicator = self.api.new_indicator(
{
"name": "testSearch",
"type": "regex",
"description": "test",
"pattern": "test[0-9]",
"diamond": "victim",
}
)
time.sleep(5)
result = self.api.search_indicators(name="testSear")
self.assertEqual(len(result), 1, result)
self.assertEqual(result[0]["name"], "testSearch")