Skip to content

Commit

Permalink
impr: fix ToS content import from file, add examples and test them in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
pandatix committed Dec 8, 2024
1 parent 286706c commit cb85c24
Show file tree
Hide file tree
Showing 14 changed files with 305 additions and 102 deletions.
19 changes: 2 additions & 17 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,31 +55,16 @@ jobs:
exit 1
fi
- name: Run functional tests
run: |
go test ./ -run=^Test_F -coverprofile=functional.out -json | tee -a gotest.json
env:
URL: http://localhost:8000

- name: Run integration test
run: |
go build -cover -o ctfd-setup cmd/ctfd-setup/main.go
mkdir coverdir
GOCOVERDIR=coverdir ./ctfd-setup
go tool covdata textfmt -i=coverdir -o integration.out
sed -i '/^\//d' integration.out
./hack/examples.sh
env:
URL: http://localhost:8000
APPEARANCE_NAME: 'CTFer.io'
APPEARANCE_DESCRIPTION: 'CTFer.io test CTFd setup'
ADMIN_NAME: 'ctfer'
ADMIN_EMAIL: '[email protected]'
ADMIN_PASSWORD: 'ctfer'

- name: Merge coverage data
run: |
go install go.shabbyrobe.org/gocovmerge/cmd/gocovmerge@fa4f82cfbf4d57c646c1ed0f35002bf1b89fbf7a
gocovmerge unit.out functional.out integration.out > cov.out
gocovmerge unit.out integration.out > cov.out
- name: Upload coverage to Coveralls
uses: shogo82148/actions-goveralls@785c9d68212c91196d3994652647f8721918ba11 # v1.9.0
Expand Down
14 changes: 11 additions & 3 deletions cmd/ctfd-setup/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func main() {
// => Pages
&cli.StringFlag{
Name: "pages.robots_txt",
Usage: "Define the /robots.txt file content, for web crawlers indexing.",
Usage: "Define the /robots.txt file content, for web crawlers indexing. Provide a path to a locally-accessible file.",
EnvVars: []string{"PAGES_ROBOTS_TXT", "PLUGIN_PAGES_ROBOTS_TXT"},
Category: configuration,
},
Expand Down Expand Up @@ -502,6 +502,14 @@ func run(ctx *cli.Context) error {
if err != nil {
return err
}
tos, err := filePtr(ctx, "legal.tos.content")
if err != nil {
return err
}
privpol, err := filePtr(ctx, "legal.privacy_policy.content")
if err != nil {
return err
}
conf := &ctfdsetup.Config{
Appearance: ctfdsetup.Appearance{
Name: ctx.String("appearance.name"),
Expand Down Expand Up @@ -585,11 +593,11 @@ func run(ctx *cli.Context) error {
Legal: &ctfdsetup.Legal{
TOS: ctfdsetup.ExternalReference{
URL: stringPtr(ctx, "legal.tos.url"),
Content: stringPtr(ctx, "legal.tos.content"),
Content: tos,
},
PrivacyPolicy: ctfdsetup.ExternalReference{
URL: stringPtr(ctx, "legal.privacy_policy.url"),
Content: stringPtr(ctx, "legal.privacy_policy.content"),
Content: privpol,
},
},
Mode: ctx.String("mode"),
Expand Down
13 changes: 10 additions & 3 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ type (
URL *string `yaml:"url,omitempty" json:"url,omitempty"`

// The content of the reference.
Content *string `yaml:"content,omitempty" json:"content,omitempty"`
Content *File `yaml:"content,omitempty" json:"content,omitempty"`
}

// Admin accesses.
Expand Down Expand Up @@ -264,8 +264,15 @@ func NewConfig() *Config {
Email: &Email{},
Time: &Time{},
Social: &Social{},
Legal: &Legal{},
Mode: "users", // default value
Legal: &Legal{
TOS: ExternalReference{
Content: &File{},
},
PrivacyPolicy: ExternalReference{
Content: &File{},
},
},
Mode: "users", // default value
}
}

Expand Down
77 changes: 0 additions & 77 deletions config_test.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
package ctfdsetup_test

import (
"context"
"os"
"path/filepath"
"testing"

ctfdsetup "github.com/ctfer-io/ctfd-setup"
"github.com/ctfer-io/go-ctfd/api"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3"
)

const (
dir = "examples"
)

func Test_U_ConfigSchema(t *testing.T) {
Expand All @@ -26,71 +17,3 @@ func Test_U_ConfigSchema(t *testing.T) {
assert.NoError(err)
assert.NotEmpty(schema)
}

func Test_F_Examples(t *testing.T) {
url, ok := os.LookupEnv("URL")
if !ok {
t.Fatal("environment variable URL is not defined")
}

files, err := os.ReadDir(dir)
if !assert.NoError(t, err) {
return
}

for _, f := range files {
if f.IsDir() {
continue
}

t.Run(f.Name(), func(t *testing.T) {
assert := assert.New(t)
ctx := context.Background()

c, err := os.ReadFile(filepath.Join(dir, f.Name()))
if !assert.NoError(err) {
return
}

// Extract config
cfg := ctfdsetup.NewConfig()
err = yaml.Unmarshal(c, cfg)
assert.NoError(err)

err = cfg.Validate()
if !assert.NoError(err) {
return
}

// Login then reset (required to run multiple test cases)
defer func() {
nonce, session, err := api.GetNonceAndSession(url, api.WithContext(ctx))
assert.NoError(err)
client := api.NewClient(url, nonce, session, "")

err = client.Login(&api.LoginParams{
Name: cfg.Admin.Name,
Password: cfg.Admin.Password.Content,
}, api.WithContext(ctx))
assert.NoError(err)

err = client.Reset(&api.ResetParams{
Accounts: ptr("true"),
Submissions: ptr("true"),
Challenges: ptr("true"),
Pages: ptr("true"),
Notifications: ptr("true"),
})
assert.NoError(err)
}()

// Setup CTFd
err = ctfdsetup.Setup(ctx, url, "", cfg)
assert.NoError(err)
})
}
}

func ptr[T any](t T) *T {
return &t
}
File renamed without changes.
32 changes: 32 additions & 0 deletions examples/nobrackets2024/.ctfd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
appearance:
name: "NoBracketsCTF 2024 - Finale"
description: ""

theme:
logo:
from_file: logo.png
small_icon:
from_file: tab-icon.png
name: core
header:
from_file: theme-header.html

settings:
challenge_visibility: public
account_visibility: public
score_visibility: private
registration_visibility: public

# Don't set time, not very usefull in replicability

legal:
tos:
content:
from_file: tos.md

mode: teams

admin:
name: 'my-name'
email: '[email protected]'
password: 'dont put password in a config file, use the varenv'
8 changes: 8 additions & 0 deletions examples/nobrackets2024/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div align="center">
<h1><img src="logo.png" width="50px"></h1>
<p><b>NoBrackets 2024</b></p>
</div>

The NoBrackets 2024 example shows how to setup CTFd for this event.

Stylesheet and images are the property of GCC and were granted free right of use by [GCC](https://github.com/gcc-ensibs)
26 changes: 26 additions & 0 deletions examples/nobrackets2024/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<div class="row">
<div class="col-md-6 offset-md-3">
<img class="w-100 mx-auto d-block" style="max-width: 600px;padding: 3vh;" src="/files/249e0a7debd973d9a53af255f42795f9/nbctf_logo_blanc.png" />
<h3 class="text-center">Concours de cybersécurité à destination des lycéennes et des lycéens</h3>
<hr>
<h4 class="text-center">Horaires de la finale :<br> 20 novembre 2024 : 10h - 16h30</h4>
<hr>
<h3 class="text-center">Créez-vous un compte puis rejoignez votre équipe avec le mot de passe fourni.</h3>
<hr>
<h1 class="text-center"><a class="btn" href="https://nobrackets.fr/docs/intro">Accès à notre Wiki</a></h1>
<h1 class="text-center"><a class="btn" href="https://discord.gg/njcQxMEkNQ">Rejoindre le Discord</a></h1>
<hr>
<h3 class="text-center">Un grand merci à nos partenaires et sponsors&nbsp;:</h3>
<img class="w-100 mx-auto d-block" style="max-width: 70%; margin-bottom: 60px; margin-top: 20px;" src="/files/91416f7326150828ae27b3bf877b4a3d/logo_PEC_blanc.png" />
<img class="w-100 mx-auto d-block" style="max-height: 10%;" src="/files/680178c26957b2cd76b6280d20d7e931/ELYSIUM_-_Logo_Root-Me_Pro_Blanc_pour_Fond_Noir.svg" />
<img class="w-100 mx-auto d-block" style="max-width: 60%; margin: 50px;" src="/files/a0ae6a1e822a1c767477531c81576d01/synacktiv-logo-blanc300.png" />
<hr>
<p class="text-justify">Le NoBracketsCTF est organisé par le club étudiant <a href="https://gcc-ensibs.fr/">Galette Cidre CTF (GCC)</a>, par des élèves des spécialités <a href="https://www-ensibs.univ-ubs.fr/fr/formations/formations/diplome-d-ingenieur-DI/sciences-technologies-sante-STS/diplome-d-ingenieur-cyberdefense-ICYB00_213.html">Cyberdéfense</a>, <a href="https://www-ensibs.univ-ubs.fr/fr/formations/formations/diplome-d-ingenieur-DI/sciences-technologies-sante-STS/diplome-d-ingenieur-cybersecurite-du-logiciel-IINF00_207.html">Cybersécurité du Logiciel</a> et <a href="https://www-ensibs.univ-ubs.fr/fr/formations/formations/diplome-d-ingenieur-DI/sciences-technologies-sante-STS/diplome-d-ingenieur-cybersecurite-et-sciences-des-donnees-KWW171GO.html">Cybersécurité et Sciences des Données</a> de <a href="https://www-ensibs.univ-ubs.fr/fr/index.html">l'Ecole Nationale Supérieure d'Ingénieurs de Bretagne Sud (ENSIBS).</a></p>
<p class="text-center">Suivez-nous sur les réseaux !</p>
<p class="text-center">
<a target="_blank" href="https://twitter.com/NoBracketsCTF"><i class="fab fa-twitter fa-2x" aria-hidden="true"></i></a>&nbsp;
<a target="_blank" href="https://www.instagram.com/nobracketsctf/"><i class="fab fa-instagram fa-2x" aria-hidden="true"></i></a>&nbsp;
<a target="_blank" href="https://discord.gg/njcQxMEkNQ"><i class="fab fa-discord fa-2x" aria-hidden="true"></i></a>
</p>
</div>
</div>
Binary file added examples/nobrackets2024/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/nobrackets2024/tab-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
98 changes: 98 additions & 0 deletions examples/nobrackets2024/theme-header.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<style id="theme-color">
.tag-Introduction > button{border: 5px solid #cad3f5; border-radius: 5px;}
.tag-Facile > button{border: 5px solid #a6da95; border-radius: 5px;}
.tag-Moyen > button{border: 5px solid #eed49f; border-radius: 5px;}
.tag-Difficile > button{border: 5px solid #ed8796; border-radius: 5px;}
.tag-D\u00e9mon > button{border: 5px solid #c6a0f6; border-radius: 5px;}

button > p::before{white-space: pre;}

.solved-challenge {
background-color: #a6da95 !important;
opacity: 100;
border-radius: 0px;
}

.tag-Introduction > button.solved-challenge {
border: 5px solid;
border-color: #a6da95;
border-radius: 5px;
}
.tag-Facile > button.solved-challenge {
border: 5px solid;
border-color: #a6da95;
border-radius: 5px;
}
.tag-Moyen > button.solved-challenge {
border: 5px solid;
border-color: #a6da95;
border-radius: 5px;
}
.tag-Difficile > button.solved-challenge {
border: 5px solid;
border-color: #a6da95;
border-radius: 5px;
}
.tag-Démon > button.solved-challenge {
border: 5px solid;
border-color: #a6da95;
border-radius: 5px;
}

body {
background-color: #212529
}
h4, .h4, h3, .h3, h2, .h2, h1, .h1 {
color: #dee2e6;
}

p, li {
color: white;
}

.challenge-desc p {
color: black;
}

.challenge-button {
&:hover {
background-color: #212529;
border-color: inherit; /* Keeps original border color on hover */
}
}

.challenge-button > p{
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
table thead td, table tbody td, table tbody tr, label{
color: #ffff;
}


h2.challenge-name, h3.challenge-value, #solves table thead td, #solves table tbody td{
color: #000000 !important;
}

h1 .btn{
padding:20px!important;
color:black!important;
background-color:white!important;
border-radius:5px!important;
font-size:20px!important;
}
h1 .btn:hover{
background-color:#48808a!important;
}

blockquote p, .card-title, .modal-body p{
color:black;
}

tr td a {
color: white;
}

</style>

Loading

0 comments on commit cb85c24

Please sign in to comment.