Skip to content

Commit

Permalink
refactor: Address bandit vulns issues
Browse files Browse the repository at this point in the history
ci: misc. changes
docs: update readme
  • Loading branch information
Nicconike committed Jun 28, 2024
1 parent 94a89a3 commit 04db6ea
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches: [ "master" ]
paths:
- ".github/workflows/codeql-pylint.yml"
- ".github/workflows/codeql.yml"
- "api/*.py"
pull_request:
branches: [ "master" ]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: "Code Coverage"
on:
workflow_dispatch:
push:
branches: [ "master" , "tests"]
branches: [ "master" ]
paths:
- ".github/workflows/coverage.yml"
- "tests/*.py"
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ name: Release

on:
push:
branches:
- master
branches: [ "master" ]
paths:
- '.github/workflows/release.yml'
- 'api/*.py'
- 'pyproject.toml'
- 'Dockerfile'
pull_request:
branches:
- master
branches: [ "master" ]

jobs:
release:
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/steam-stats.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ on:
- cron: "30 18 * * 0"
workflow_dispatch:
push:
branches:
- master
branches: [ "master" ]
paths:
- '.github/workflows/steam-stats.yml'
- 'api/*.py'
pull_request:
branches:
- master
branches: [ "master" ]

jobs:
update-readme:
Expand Down
49 changes: 30 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# 🛠️Work in Progress 🚧|🚧 Please come back later⚒️
[![Steam Stats](https://github.com/Nicconike/Steam-Stats/actions/workflows/steam-stats.yml/badge.svg)](https://github.com/Nicconike/Steam-Stats/actions/workflows/steam-stats.yml)
[![Release](https://github.com/Nicconike/Steam-Stats/actions/workflows/release.yml/badge.svg)](https://github.com/Nicconike/Steam-Stats/actions/workflows/release.yml)
[![CodeQL & Pylint](https://github.com/Nicconike/Steam-Stats/actions/workflows/codeql-pylint.yml/badge.svg)](https://github.com/Nicconike/Steam-Stats/actions/workflows/codeql-pylint.yml)
[![CodeQL & Pylint](https://github.com/Nicconike/Steam-Stats/actions/workflows/codeql.yml/badge.svg)](https://github.com/Nicconike/Steam-Stats/actions/workflows/codeql.yml)
[![Bandit](https://github.com/Nicconike/Steam-Stats/actions/workflows/sast.yml/badge.svg)](https://github.com/Nicconike/Steam-Stats/actions/workflows/sast.yml)
![pylint](https://img.shields.io/badge/PyLint-10.00-brightgreen?logo=python&logoColor=white)
[![codecov](https://codecov.io/gh/Nicconike/Steam-Stats/graph/badge.svg?token=SC5P7CS1BW)](https://codecov.io/gh/Nicconike/Steam-Stats)
Expand Down Expand Up @@ -63,7 +63,7 @@ schedule:
3. Don't forget to add these comments in your readme file or wherever you want to display your steam stats, because without the comments the readme will not get updated
***
## Features
1. Steam Player Summary[^*]
1. Steam Player Summary[^1]
2. Recently Played Games from Steam in the Last 2 Weeks
3. Steam Workshop Stats (If Available)

Expand Down Expand Up @@ -112,32 +112,43 @@ jobs:
STEAM_CUSTOM_ID: ${{ vars.STEAM_CUSTOM_ID }}
```
***
## Contributing
## Contributions



Please refer [Contributing.md](https://github.com/Nicconike/Steam-Stats/blob/master/.github/CONTRIBUTING.md) to get to know how to contribute to this project.
And thank you for considering to contribute.

***
## Credits

- **GitHub Actions**
- [Checkout](https://github.com/actions/checkout)
- [Setup-Python](https://github.com/actions/setup-python)
- [Cache](https://github.com/actions/cache)
- [Upload-Artifact](https://github.com/actions/upload-artifact)
- [Create-Github-App-Token](https://github.com/actions/create-github-app-token)
- [CodeQL-Action](https://github.com/github/codeql-action)
- [Pylint-Github-Action](https://github.com/Silleellie/pylint-github-action)
- [Python-Semantic-Release](https://github.com/python-semantic-release/python-semantic-release)
- [Setup-Buildx-Action](https://github.com/docker/setup-buildx-action)
- [Login-Action](https://github.com/docker/login-action)
- [Metadata-Action](https://github.com/docker/metadata-action)
- [Build-Push-Action](https://github.com/docker/build-push-action)
- [Scout-Action](https://github.com/docker/scout-action)
- **Actions**
- **GitHub Actions**
- [Checkout](https://github.com/actions/checkout)
- [Setup-Python](https://github.com/actions/setup-python)
- [Cache](https://github.com/actions/cache)
- [Upload-Artifact](https://github.com/actions/upload-artifact)
- [Create-Github-App-Token](https://github.com/actions/create-github-app-token)
- **Semantic Release**
- [Python-Semantic-Release](https://github.com/python-semantic-release/python-semantic-release)
- **Docker**
- [Setup-Buildx-Action](https://github.com/docker/setup-buildx-action)
- [Login-Action](https://github.com/docker/login-action)
- [Metadata-Action](https://github.com/docker/metadata-action)
- [Build-Push-Action](https://github.com/docker/build-push-action)
- [Scout-Action](https://github.com/docker/scout-action)
- **CodeQL**
- [CodeQL-Action](https://github.com/github/codeql-action)
- **Pylint**
- [Pylint-Github-Action](https://github.com/Silleellie/pylint-github-action)
- **Codecov**
- [Codecov-Action](https://github.com/codecov/codecov-action)
- **Styles**
- [Progress Bar Design](https://github.com/Nicconike/Steam-Stats/blob/master/assets/style.css) - [Ana Tudor](https://codepen.io/thebabydino)
- [Progress Bar Design](https://github.com/Nicconike/Steam-Stats/blob/master/assets/style.css)[^2] - [Ana Tudor](https://codepen.io/thebabydino)

***
Created with Game Sense & ❤️ by [Nicco](https://github.com/Nicconike)

[^*]: Unfortunately, Steam Web API doesn't support Web Sockets so the profile status cannot be updated in real time as it gets updated in steam profile 🥲
[^1]: Unfortunately, Steam Web API doesn't support Web Sockets so the profile status cannot be updated in real time as it gets updated in steam profile 🥲

[^2]: Modified `style.css` code according to my requirements
Binary file modified requirements.txt
Binary file not shown.
25 changes: 17 additions & 8 deletions tests/test_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ async def test_get_element_bounding_box():
return_value=mock_browser)

result = await get_element_bounding_box(html_file, selector)
assert result == bounding_box
if result != bounding_box:
raise AssertionError(f"Expected result to be {bounding_box}")


@pytest.mark.asyncio
Expand Down Expand Up @@ -88,7 +89,8 @@ def test_format_unix_time():
unix_time = 1609459200 # 01/01/2021 @ 12:00am (UTC)
expected = "01/01/2021"
result = format_unix_time(unix_time)
assert result == expected
if result != expected:
raise AssertionError(f"Expected result to be {expected}")


def test_generate_card_for_player_summary():
Expand All @@ -107,8 +109,10 @@ def test_generate_card_for_player_summary():
}
}
result = generate_card_for_player_summary(player_data)
assert result is not None
assert "![Steam Summary]" in result
if result is None:
raise AssertionError("Result should not be None")
if "![Steam Summary]" not in result:
raise AssertionError("Result should contain '![Steam Summary]'")


def test_generate_card_for_played_games():
Expand All @@ -124,8 +128,11 @@ def test_generate_card_for_played_games():
}
}
result = generate_card_for_played_games(games_data)
assert result is not None
assert "![Recently Played Games]" in result
if result is None:
raise AssertionError("Result should not be None")
if "![Recently Played Games]" not in result:
raise AssertionError(
"Result should contain '![Recently Played Games]'")


def test_generate_card_for_steam_workshop():
Expand All @@ -136,5 +143,7 @@ def test_generate_card_for_steam_workshop():
"total_current_favorites": 200
}
result = generate_card_for_steam_workshop(workshop_stats)
assert result is not None
assert "![Steam Workshop Stats]" in result
if result is None:
raise AssertionError("Result should not be None")
if "![Steam Workshop Stats]" not in result:
raise AssertionError("Result should contain '![Steam Workshop Stats]'")
40 changes: 25 additions & 15 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ def test_get_player_summaries_success(requests_mock):
}]}}
)
result = main.get_player_summaries()
assert result is not None
assert "response" in result
assert "players" in result["response"]
if result is None:
raise AssertionError("Expected result to be not None")
if result is None or "response" not in result:
raise AssertionError("Expected 'response' to be in result")
if "players" not in result["response"]:
raise AssertionError("Expected 'players' to be in result['response']")


def test_get_recently_played_games_success(requests_mock):
Expand All @@ -39,9 +42,12 @@ def test_get_recently_played_games_success(requests_mock):
]}}
)
result = main.get_recently_played_games()
assert result is not None
assert "response" in result
assert "games" in result["response"]
if result is None:
raise AssertionError("Expected result to be not None")
if result is None or "response" not in result:
raise AssertionError("Expected 'response' to be in result")
if "games" not in result["response"]:
raise AssertionError("Expected 'games' to be in result['response']")


def test_get_recently_played_games_no_games(requests_mock):
Expand All @@ -51,7 +57,8 @@ def test_get_recently_played_games_no_games(requests_mock):
json={"response": {"total_count": 0}}
)
result = main.get_recently_played_games()
assert result is None
if result is not None:
raise AssertionError("Expected result to be None")


def test_fetch_workshop_item_links_success(requests_mock):
Expand All @@ -66,8 +73,10 @@ def test_fetch_workshop_item_links_success(requests_mock):
json={"servertime": 1234567890}
)
result = main.fetch_workshop_item_links("dummy_custom_id", "dummy_api_key")
assert result == [
expected_result = [
"https://steamcommunity.com/sharedfiles/filedetails/?id=2984474065"]
if result != expected_result:
raise AssertionError(f"Result should be {expected_result}")


def test_generate_steam_stats(requests_mock):
Expand All @@ -88,35 +97,36 @@ def test_generate_steam_stats(requests_mock):
]}}
)
result = main.generate_steam_stats()
assert "![Steam Summary]" in result
assert "![Recently Played Games]" in result
if "![Steam Summary]" not in result:
raise AssertionError("Expected '![Steam Summary]' to be in result")
if "![Recently Played Games]" not in result:
raise AssertionError(
"Expected '![Recently Played Games]' to be in result")


def test_generate_workshop_stats(requests_mock):
"""Test generating Workshop stats"""
# Mock the initial request to fetch workshop item links
requests_mock.get(
'https://steamcommunity.com/id/nicconike/myworkshopfiles/?p=1',
text='<div class="workshopItem"><a class="ugc"'
'href="https://steamcommunity.com/sharedfiles/filedetails/?id=2984474065"></a></div>'
)
# Mock the server info request
requests_mock.get(
'https://api.steampowered.com/ISteamWebAPIUtil/GetServerInfo/v1/',
json={"servertime": 1234567890}
)
# Mock the request to fetch individual workshop stats
requests_mock.get(
'https://steamcommunity.com/sharedfiles/filedetails/?id=2984474065',
text='<table class="stats_table"><tr><td>1,000</td><td>Unique Visitors</td></tr></table>'
)
# Mock the next page request if applicable
requests_mock.get(
'https://steamcommunity.com/id/dummy_custom_id/myworkshopfiles/?p=2',
text=''
)
result = main.generate_workshop_stats()
assert "![Steam Workshop Stats]" in result
if "![Steam Workshop Stats]" not in result:
raise AssertionError(
"Expected '![Steam Workshop Stats]' to be in result")


def test_main(requests_mock):
Expand Down
33 changes: 22 additions & 11 deletions tests/test_steam_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ def test_get_player_summaries_success(requests_mock):
json={"response": {"players": []}}
)
result = get_player_summaries()
assert result is not None
assert "response" in result
assert "players" in result["response"]
if result is None:
raise AssertionError("Expected result to be not None")
if result is None or "response" not in result:
raise AssertionError("Expected 'response' to be in result")
if "players" not in result["response"]:
raise AssertionError("Expected 'players' to be in result['response']")


def test_get_player_summaries_http_error(requests_mock):
Expand All @@ -32,7 +35,8 @@ def test_get_player_summaries_http_error(requests_mock):
status_code=404
)
result = get_player_summaries()
assert result is None
if result is not None:
raise AssertionError("Expected result to be None")


def test_get_player_summaries_request_exception(requests_mock):
Expand All @@ -42,7 +46,8 @@ def test_get_player_summaries_request_exception(requests_mock):
exc=requests.exceptions.RequestException
)
result = get_player_summaries()
assert result is None
if result is not None:
raise AssertionError("Expected result to be None")


def test_get_recently_played_games_success(requests_mock):
Expand All @@ -53,9 +58,12 @@ def test_get_recently_played_games_success(requests_mock):
{"name": "TestGame", "playtime_2weeks": 120}]}}
)
result = get_recently_played_games()
assert result is not None
assert "response" in result
assert "games" in result["response"]
if result is None:
raise AssertionError("Expected result to be not None")
if result is None or "response" not in result:
raise AssertionError("Expected 'response' to be in result")
if "games" not in result["response"]:
raise AssertionError("Expected 'games' to be in result['response']")


def test_get_recently_played_games_no_games(requests_mock):
Expand All @@ -65,7 +73,8 @@ def test_get_recently_played_games_no_games(requests_mock):
json={"response": {"total_count": 0}}
)
result = get_recently_played_games()
assert result is None
if result is not None:
raise AssertionError("Expected result to be None")


def test_get_recently_played_games_http_error(requests_mock):
Expand All @@ -75,7 +84,8 @@ def test_get_recently_played_games_http_error(requests_mock):
status_code=404
)
result = get_recently_played_games()
assert result is None
if result is not None:
raise AssertionError("Expected result to be None")


def test_get_recently_played_games_request_exception(requests_mock):
Expand All @@ -85,4 +95,5 @@ def test_get_recently_played_games_request_exception(requests_mock):
exc=requests.exceptions.RequestException
)
result = get_recently_played_games()
assert result is None
if result is not None:
raise AssertionError("Expected result to be None")
Loading

0 comments on commit 04db6ea

Please sign in to comment.