Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Adding test to auth #7

Merged
merged 66 commits into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
5d533ce
chore: Update go version to 1.22 and gofakeit/v7 dependency to v7.0.4
doziestar Jul 5, 2024
62dddde
feat: Update user authentication logic in Login function
doziestar Jul 5, 2024
f19c2af
feat: Update user authentication logic in Login function
doziestar Jul 5, 2024
fa520a2
feat: Update user authentication logic in Login function
doziestar Jul 5, 2024
6d2fbcc
chore: Update role search query to use name prefix instead of contains
doziestar Jul 5, 2024
874a6b2
feat: Add token repository tests for create, getByToken, revokeToken,…
doziestar Jul 5, 2024
6fbcef4
chore: Refactor token revocation logic in TokenRepository
doziestar Jul 5, 2024
f6da9b4
feat: Refactor token revocation logic, update role search query, and …
doziestar Jul 5, 2024
02365a3
chore: Update user authentication logic in Login function
doziestar Jul 5, 2024
fcd0304
feat: Add password hashing functionality
doziestar Jul 5, 2024
d0e2a30
chore: Add error types for empty password and invalid bcrypt cost
doziestar Jul 5, 2024
b84516d
feat: Add Base64Encoder for encoding and decoding Base64 strings
doziestar Jul 5, 2024
993699c
Add unit tests for Base64Encoder
doziestar Jul 5, 2024
a239b45
feat: Add TokenGenerator for generating JWT tokens
doziestar Jul 5, 2024
dfb88c5
feat: Add unit tests for TokenGenerator and Base64Encoder
doziestar Jul 5, 2024
326b599
feat: Add PerIPRateLimiter for per-IP rate limiting
doziestar Jul 5, 2024
d67d1c8
Add unit tests for PerIPRateLimiter
doziestar Jul 5, 2024
6d2b2c9
chore: Refactor user_test.go and improve test coverage
doziestar Jul 5, 2024
3c821d6
chore: Refactor token_test.go and improve test coverage
doziestar Jul 5, 2024
dc91d8c
feat: Refactor code for improved test coverage and add new functionality
doziestar Jul 5, 2024
a8415db
chore: Refactor role_test.go for improved test coverage and remove un…
doziestar Jul 5, 2024
c8d9eff
feat: Add WithAPIKeyCache option for setting API key cache
doziestar Jul 5, 2024
2c19a92
Refactor code for improved test coverage and add new functionality
doziestar Jul 5, 2024
f787c85
chore: Refactor db.go for improved test coverage and remove unnecessa…
doziestar Jul 5, 2024
18daad3
Refactor user.go to use pkg.NewPasswordHasher for password hashing
doziestar Jul 5, 2024
fe739ef
Refactor password_hash.go for improved password verification and erro…
doziestar Jul 5, 2024
0308e14
Refactor auth interceptor test for improved test coverage and error h…
doziestar Jul 5, 2024
d968b64
Refactor code for improved test coverage and error handling
doziestar Jul 5, 2024
8e6f02a
Refactor code for improved test coverage and error handling
doziestar Jul 5, 2024
1d1f2c4
feat: Refactor user_test.go for improved password hashing and error h…
doziestar Jul 5, 2024
da92b13
Refactor user.go to use pkg.NewPasswordHasher for password hashing
doziestar Jul 5, 2024
5dc27e4
Refactor .gitignore to exclude .idea, .vscode, and log files
doziestar Jul 5, 2024
2584649
refactor: Add Is method to Error struct for compatibility with errors…
doziestar Jul 5, 2024
0deba72
chore: Add initial configuration file with JWT secret and service add…
doziestar Jul 5, 2024
0235a14
refactor: Update auth interceptor to refresh token and add new token …
doziestar Jul 5, 2024
8e61c6d
Refactor code for improved test coverage and error handling
doziestar Jul 5, 2024
b435805
refactor: Update auth interceptor to use "APIKey" instead of "ApiKey"…
doziestar Jul 5, 2024
f6db554
Refactor code for improved test coverage and error handling
doziestar Jul 5, 2024
574915c
refactor: Update password_hash.go, interceptor.go, token_generator_te…
doziestar Jul 5, 2024
1794ec9
refactor: Add unit tests for user, role, and token schemas
doziestar Jul 5, 2024
6d65afa
refactor: Update password hashing tests to use VerifyPassword method
doziestar Jul 5, 2024
86b1c51
refactor: Update user client hooks to include user.Hooks
doziestar Jul 5, 2024
50cbc54
refactor: Update CI/CD workflow to use Go 1.21 and add unit tests for…
doziestar Jul 5, 2024
bce2aaa
refactor: Update password hashing tests to use VerifyPassword method
doziestar Jul 5, 2024
35a1f6a
refactor: Update password hashing tests to use VerifyPassword method
doziestar Jul 5, 2024
2dc707a
refactor: Update user repository to handle user not found error in Se…
doziestar Jul 5, 2024
daf9126
refactor: Update Go module dependencies to latest versions
doziestar Jul 5, 2024
d8b4c3d
refactor: Update CI/CD workflow to use Go 1.21 and add unit tests for…
doziestar Jul 5, 2024
65ef121
refactor: Update GitHub Pages deployment token in CI/CD workflow
doziestar Jul 5, 2024
54d4804
refactor: Improve formatting check in CI/CD workflow
doziestar Jul 5, 2024
7410adb
add pre-commit
doziestar Jul 5, 2024
dfa66dd
refactor: Add main package to internal/ai/cmd/main.go
doziestar Jul 5, 2024
9aa00bd
refactor: Remove unused code in ConnectorFactory function
doziestar Jul 5, 2024
e493a94
refactor: Remove unused code in ConnectorFactory function
doziestar Jul 5, 2024
f9fd3aa
refactor: Remove unused code in ConnectorFactory function
doziestar Jul 5, 2024
27f42b8
refactor: Remove unused code in ConnectorFactory function
doziestar Jul 5, 2024
cbc88f2
refactor: Update grpc.Dial to grpc.NewClient in main.go
doziestar Jul 5, 2024
5381de3
refactor: Update grpc.Dial to grpc.NewClient in main.go
doziestar Jul 5, 2024
7c2529a
refactor: Enable gRPC secure connection in DataSourceClient
doziestar Jul 5, 2024
b29c1e0
refactor: Enable gRPC secure connection in DataSourceClient
doziestar Jul 5, 2024
453a8e7
refactor: Enable gRPC secure connection in DataSourceClient
doziestar Jul 5, 2024
c7a4c80
refactor: Remove unused code and add main package to internal/ai/cmd/…
doziestar Jul 6, 2024
9b4c0ad
refactor: Remove unused code and add main package to internal/ai/cmd/…
doziestar Jul 6, 2024
bc7503a
refactor: Fix capitalization of error type in APIConnector
doziestar Jul 6, 2024
53afa68
refactor: Remove coverage.txt files from gitignore
doziestar Jul 6, 2024
946d24a
refactor: Remove unused code and add main package to internal/ai/cmd/…
doziestar Jul 6, 2024
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
21 changes: 21 additions & 0 deletions .fleet/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"editor.formatOnSave": true,
"plugins": [
{
"type": "add",
"pluginName": "fleet.ai"
},
{
"type": "add",
"pluginName": "fleet.go.ai"
},
{
"type": "add",
"pluginName": "fleet.python.ai"
},
{
"type": "add",
"pluginName": "fleet.rust.ai"
}
]
}
134 changes: 134 additions & 0 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
name: Go CI/CD

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.22"
- name: Verify workspace
run: go work sync
- name: Check formatting
run: |
all_formatted=true
for dir in $(go work edit -json | jq -r '.Use[].DiskPath'); do
echo "Checking formatting in $dir"
if [ -n "$(gofmt -s -l $dir)" ]; then
echo "Formatting issues in $dir:"
gofmt -s -l $dir
all_formatted=false
else
echo "No formatting issues in $dir"
fi
done
if [ "$all_formatted" = false ]; then
echo "Formatting errors found. Please run 'go fmt ./...' in each module to fix."
exit 1
fi
- name: Run go vet
run: |
for dir in $(go work edit -json | jq -r '.Use[].DiskPath'); do
echo "Running go vet in $dir"
go vet ./$dir/...
done

# - name: Run goimports
# run: |
# for dir in $(go work edit -json | jq -r '.Use[].DiskPath'); do
# echo "Running goimports in $dir"
# goimports -l $dir
# done

# - name: Run gocyclo
# run: |
# for dir in $(go work edit -json | jq -r '.Use[].DiskPath'); do
# echo "Running gocyclo in $dir"
# gocyclo -over 15 $dir
# done

# - name: Static check
# run: |
# for dir in $(go work edit -json | jq -r '.Use[].DiskPath'); do
# echo "Running staticcheck in $dir"
# staticcheck $dir
# done

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.22"
- name: Run tests
run: |
go work use .
for dir in $(go work edit -json | jq -r '.Use[].DiskPath'); do
echo "Running tests in $dir"
go test -v -race -coverprofile=$dir/coverage.txt -covermode=atomic ./$dir/...
done
- name: Combine coverage
run: |
echo "mode: atomic" > coverage.txt
for dir in $(go work edit -json | jq -r '.Use[].DiskPath'); do
if [ -f $dir/coverage.txt ]; then
tail -n +2 $dir/coverage.txt >> coverage.txt
fi
done
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ./coverage.txt
- name: Upload coverage artifact
uses: actions/upload-artifact@v2
with:
name: coverage
path: coverage.txt

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.22"
- name: Build
run: |
for dir in $(go work edit -json | jq -r '.Use[].DiskPath'); do
echo "Building in $dir"
go build -v ./$dir/...
done

deploy-coverage:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Download coverage artifact
uses: actions/download-artifact@v2
with:
name: coverage
- name: Generate coverage HTML
run: |
go tool cover -html=coverage.txt -o coverage.html
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.TOKEN }}
publish_dir: .
publish_branch: gh-pages
keep_files: true
user_name: "github-actions[bot]"
user_email: "github-actions[bot]@users.noreply.github.com"
commit_message: "Deploy coverage report to GitHub Pages"
43 changes: 0 additions & 43 deletions .github/workflows/deploy.yml

This file was deleted.

30 changes: 27 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,31 @@
# vendor/

# Go workspace file
go.work
go.work.sum
# go.work
# go.work.sum

.env
.env
.fleet
.idea
.vscode
*.log
*.log.*
*.log-*
.DS_Store


node_modules

web/node_modules
datavinci
ai
report
realtime

/internal/auth/coverage.txt
/internal/datasource/coverage.txt
/internal/visualization/coverage.txt
/internal/realtime/coverage.txt
/internal/report/coverage.txt
/internal/ai/coverage.txt
/pkg/coverage.txt
2 changes: 1 addition & 1 deletion .idea/datavinci.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 52 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
args: [--allow-multiple-documents]
# - id: check-added-large-files
# args: [--maxkb=1000]

# - repo: https://github.com/golangci/golangci-lint
# rev: v1.54.2
# hooks:
# - id: golangci-lint

- repo: https://github.com/dnephin/pre-commit-golang
rev: v0.5.1
hooks:
- id: go-fmt
# - id: go-vet
# files: \.go$
# exclude: ^datavinci/
- id: go-imports
- id: go-cyclo
# args: [-over=15]
- id: validate-toml
- id: no-go-testing
# - id: go-critic
# args: [--disable=sloppyTypeAssert]
- id: go-unit-tests
- id: go-build
- id: go-mod-tidy

# - repo: https://github.com/pre-commit/mirrors-prettier
# rev: v3.0.3
# hooks:
# - id: prettier
# types_or: [javascript, jsx, ts, tsx, json]
# files: ^web/

# - repo: https://github.com/pre-commit/mirrors-eslint
# rev: v8.49.0
# hooks:
# - id: eslint
# files: ^web/.*\.[jt]sx?$ # *.js, *.jsx, *.ts and *.tsx in web folder
# types: [file]
# additional_dependencies:
# - eslint@9.6.0
# - typescript@5.2.2
# - "@typescript-eslint/parser@6.7.0"
# - "@typescript-eslint/eslint-plugin@6.7.0"
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ FROM alpine:latest
WORKDIR /root/
COPY --from=builder /app/datavinci .
EXPOSE 8080
CMD ["./datavinci"]
CMD ["./datavinci"]
Loading
Loading