diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 6e85db5..3aa8307 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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 @@ -52,9 +55,22 @@ jobs: fi - name: Setup CTFd - run: go run cmd/setup/main.go + uses: ctfer-io/ctfd-setup@affeb6f227e6aa768f71e0c1b5f08d80f2eca2e2 # v1.1.2 + with: + url: http://localhost:8080 + appearance_name: TFP-CTFd + appearance_description: Terraform Provider CTFd. + mode: teams + admin_name: ${{ env.NAME }} + admin_email: ctfer-io@protonmail.com + 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 diff --git a/cmd/setup/main.go b/cmd/token/main.go similarity index 52% rename from cmd/setup/main.go rename to cmd/token/main.go index f11a927..aa2554e 100644 --- a/cmd/setup/main.go +++ b/cmd/token/main.go @@ -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: "ctfer-io@protonmail.com", - 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