MCPcopy
hub / github.com/crowdsecurity/crowdsec / TestAPICPullTopBLCacheForceCall

Function TestAPICPullTopBLCacheForceCall

pkg/apiserver/apic_test.go:878–952  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

876}
877
878func TestAPICPullTopBLCacheForceCall(t *testing.T) {
879 ctx := t.Context()
880 api := getAPIC(t, ctx)
881
882 httpmock.Activate()
883 defer httpmock.DeactivateAndReset()
884
885 // create a decision about to expire. It should force fetch
886 alertInstance := api.dbClient.Ent.Alert.
887 Create().
888 SetScenario("update list").
889 SetSourceScope("list:blocklist1").
890 SetSourceValue("list:blocklist1").
891 SaveX(ctx)
892
893 api.dbClient.Ent.Decision.Create().
894 SetOrigin(types.ListOrigin).
895 SetType("ban").
896 SetValue("9.9.9.9").
897 SetScope("Ip").
898 SetScenario("blocklist1").
899 SetUntil(time.Now().Add(time.Hour)).
900 SetOwnerID(alertInstance.ID).
901 ExecX(ctx)
902
903 httpmock.RegisterResponder("GET", "http://api.crowdsec.net/api/decisions/stream", httpmock.NewBytesResponder(
904 200, jsonMarshalX(
905 modelscapi.GetDecisionsStreamResponse{
906 New: modelscapi.GetDecisionsStreamResponseNew{
907 &modelscapi.GetDecisionsStreamResponseNewItem{
908 Scenario: new("crowdsecurity/test1"),
909 Scope: new("Ip"),
910 Decisions: []*modelscapi.GetDecisionsStreamResponseNewItemDecisionsItems0{
911 {
912 Value: new("1.2.3.4"),
913 Duration: new("24h"),
914 },
915 },
916 },
917 },
918 Links: &modelscapi.GetDecisionsStreamResponseLinks{
919 Blocklists: []*modelscapi.BlocklistLink{
920 {
921 URL: new("http://api.crowdsec.net/blocklist1"),
922 Name: new("blocklist1"),
923 Scope: new("Ip"),
924 Remediation: new("ban"),
925 Duration: new("24h"),
926 },
927 },
928 },
929 },
930 ),
931 ))
932
933 httpmock.RegisterResponder("GET", "http://api.crowdsec.net/blocklist1", func(req *http.Request) (*http.Response, error) {
934 assert.Empty(t, req.Header.Get("If-Modified-Since"))
935 return httpmock.NewStringResponse(304, ""), nil

Callers

nothing calls this directly

Calls 15

NewDefaultClientFunction · 0.92
getAPICFunction · 0.85
jsonMarshalXFunction · 0.85
EmptyMethod · 0.80
PullTopMethod · 0.80
SaveXMethod · 0.45
SetSourceValueMethod · 0.45
SetSourceScopeMethod · 0.45
SetScenarioMethod · 0.45
CreateMethod · 0.45
ExecXMethod · 0.45
SetOwnerIDMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…