(t *testing.T)
| 876 | } |
| 877 | |
| 878 | func 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 |
nothing calls this directly
no test coverage detected
searching dependent graphs…