Skip to content

Commit

Permalink
ci: defer setup to ctfer-io/ctfd-setup action
Browse files Browse the repository at this point in the history
  • Loading branch information
pandatix committed Jun 1, 2024
1 parent 0a02f4a commit 19091e3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 27 deletions.
18 changes: 17 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ jobs:
image: ctfd/ctfd:3.7.0@sha256:e4e886aa8f1051eeddcabe2115bc9a5f380be2b54034d5a119c44b177d6b8c57
ports:
- 8000:8000
env:
NAME: ctfer
PASSWORD: password
steps:
- name: Checkout code
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
Expand Down Expand Up @@ -52,9 +55,22 @@ jobs:
fi
- name: Setup CTFd
run: go run cmd/setup/main.go
uses: ctfer-io/ctfd-setup@57372d692063dfb4ec205edde8e7b2b225e0c752 # v1.1.0
with:
url: http://localhost:8080
appearance_name: TFP-CTFd
appearance_description: Terraform Provider CTFd.
mode: teams
admin_name: ${{ env.NAME }}
admin_email: [email protected]
admin_password: ${{ env.PASSWORD }}

- name: Generate token
run: go run cmd/token/main.go
env:
CTFD_URL: http://localhost:8000
CTFD_NAME: ${{ env.NAME }}
CTFD_PASSWORD: ${{ env.PASSWORD }}

- name: Run go acceptance tests
run: make test-acc
Expand Down
35 changes: 9 additions & 26 deletions cmd/setup/main.go → cmd/token/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,27 @@ import (
"github.com/ctfer-io/go-ctfd/api"
)

// This utility setup a brand new CTFd instance for acceptance testing of the provider,
// This utility login to a CTFd instance for acceptance testing of the provider,
// and creates an API key ready to work.

func main() {
url := os.Getenv("CTFD_URL")
name := os.Getenv("CTFD_NAME")
password := os.Getenv("CTFD_PASSWORD")

// Note: add /setup so won't have to follow redirect
fmt.Println("[+] Getting initial nonce and session values")
nonce, session, err := api.GetNonceAndSession(url)
if err != nil {
log.Fatalf("Getting nonce and session: %s", err)
}

// Setup CTFd
fmt.Println("[+] Setting up CTFd")
client := api.NewClient(url, nonce, session, "")
if err := client.Setup(&api.SetupParams{
CTFName: "TFP-CTFd",
CTFDescription: "Terraform Provider CTFd.",
UserMode: "teams",
Name: "ctfer",
Email: "[email protected]",
Password: "ctfer",
ChallengeVisibility: "public",
AccountVisibility: "public",
ScoreVisibility: "public",
RegistrationVisibility: "public",
VerifyEmails: false,
TeamSize: nil,
CTFLogo: nil,
CTFBanner: nil,
CTFSmallIcon: nil,
CTFTheme: "core",
ThemeColor: "",
Start: "",
End: "",

fmt.Println("[+] Logging in")
if err := client.Login(&api.LoginParams{
Name: name,
Password: password,
}); err != nil {
log.Fatalf("Setting up CTFd: %s", err)
log.Fatalf("Logging in: %s", err)
}

// Create API Key
Expand Down

0 comments on commit 19091e3

Please sign in to comment.