MCPcopy Index your code
hub / github.com/crowdsecurity/crowdsec / LoadTestConfigForwardedFor

Function LoadTestConfigForwardedFor

pkg/apiserver/apiserver_test.go:99–138  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

97}
98
99func LoadTestConfigForwardedFor(t *testing.T) csconfig.Config {
100 config := csconfig.Config{}
101 maxAge := cstime.DurationWithDays(1 * time.Hour)
102 flushConfig := csconfig.FlushDBCfg{
103 MaxAge: maxAge,
104 }
105
106 tempDir, _ := os.MkdirTemp("", "crowdsec_tests")
107
108 t.Cleanup(func() { os.RemoveAll(tempDir) })
109
110 dbconfig := csconfig.DatabaseCfg{
111 Type: "sqlite",
112 DbPath: filepath.Join(tempDir, "ent"),
113 Flush: &flushConfig,
114 }
115 apiServerConfig := csconfig.LocalApiServerCfg{
116 ListenURI: "http://127.0.0.1:8080",
117 DbConfig: &dbconfig,
118 ProfilesPath: "./tests/profiles.yaml",
119 UseForwardedForHeaders: true,
120 TrustedProxies: &[]string{"0.0.0.0/0"},
121 ConsoleConfig: &csconfig.ConsoleConfig{
122 ShareManualDecisions: new(bool),
123 ShareTaintedScenarios: new(bool),
124 ShareCustomScenarios: new(bool),
125 },
126 }
127 apiConfig := csconfig.APICfg{
128 Server: &apiServerConfig,
129 }
130 config.API = &apiConfig
131 err := config.API.Server.LoadProfiles()
132 require.NoError(t, err)
133
134 err = config.API.Server.LoadAutoRegister()
135 require.NoError(t, err)
136
137 return config
138}
139
140func NewAPIServer(t *testing.T, ctx context.Context) (*APIServer, csconfig.Config) {
141 config := LoadTestConfig(t)

Callers 1

NewAPITestForwardedForFunction · 0.85

Calls 2

LoadProfilesMethod · 0.80
LoadAutoRegisterMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…