1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
package main
import (
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
"testing"
)
func TestCreateApplicationContext(t *testing.T) {
wrapper := NewTestStorageWrapper(t)
wrapper.AddCollection(Settings)
appContext, err := CreateApplicationContext(wrapper.Storage)
assert.NoError(t, err)
assert.False(t, appContext.IsConfigured)
assert.Zero(t, appContext.Config)
assert.Len(t, appContext.Accounts, 0)
assert.Nil(t, appContext.PcapImporter)
assert.Nil(t, appContext.RulesManager)
config := Config{
ServerAddress: "10.10.10.10",
FlagRegex: "FLAG{test}",
AuthRequired: true,
}
accounts := gin.Accounts{
"username": "password",
}
appContext.SetConfig(config)
appContext.SetAccounts(accounts)
assert.Equal(t, appContext.Config, config)
assert.Equal(t, appContext.Accounts, accounts)
assert.NotNil(t, appContext.PcapImporter)
assert.NotNil(t, appContext.RulesManager)
assert.True(t, appContext.IsConfigured)
config.FlagRegex = "FLAG{test2}"
accounts["username"] = "password2"
appContext.SetConfig(config)
appContext.SetAccounts(accounts)
checkAppContext, err := CreateApplicationContext(wrapper.Storage)
assert.NoError(t, err)
assert.True(t, checkAppContext.IsConfigured)
assert.Equal(t, checkAppContext.Config, config)
assert.Equal(t, checkAppContext.Accounts, accounts)
assert.NotNil(t, checkAppContext.PcapImporter)
assert.NotNil(t, checkAppContext.RulesManager)
wrapper.Destroy(t)
}
|