forked from gane5hvarma/panther
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kostas Papageorgiou
authored
Dec 17, 2020
1 parent
04073f9
commit 5fd1587
Showing
14 changed files
with
285 additions
and
238 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
internal/log_analysis/alert_forwarder/forwarder/rule_cache_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package forwarder | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/mock" | ||
|
||
"github.com/panther-labs/panther/api/lambda/analysis/models" | ||
"github.com/panther-labs/panther/pkg/testutils" | ||
) | ||
|
||
/** | ||
* Panther is a Cloud-Native SIEM for the Modern Security Team. | ||
* Copyright (C) 2020 Panther Labs Inc | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
func TestCacheHttpError(t *testing.T) { | ||
t.Parallel() | ||
ruleClientMock := &testutils.GatewayapiMock{} | ||
cache := NewCache(ruleClientMock) | ||
|
||
ruleClientMock.On("Invoke", mock.Anything, mock.Anything).Return(http.StatusInternalServerError, nil).Once() | ||
rule, err := cache.Get("id", "version") | ||
assert.Error(t, err) | ||
assert.Nil(t, rule) | ||
ruleClientMock.AssertExpectations(t) | ||
} | ||
|
||
func TestCacheInvocationError(t *testing.T) { | ||
t.Parallel() | ||
ruleClientMock := &testutils.GatewayapiMock{} | ||
cache := NewCache(ruleClientMock) | ||
|
||
ruleClientMock.On("Invoke", mock.Anything, mock.Anything).Return(0, errors.New("test")).Once() | ||
rule, err := cache.Get("id", "version") | ||
assert.Error(t, err) | ||
assert.Nil(t, rule) | ||
ruleClientMock.AssertExpectations(t) | ||
} | ||
|
||
func TestCacheRuleRetrieval(t *testing.T) { | ||
t.Parallel() | ||
ruleClientMock := &testutils.GatewayapiMock{} | ||
cache := NewCache(ruleClientMock) | ||
|
||
expectedInput := &models.LambdaInput{ | ||
GetRule: &models.GetRuleInput{ID: "id", VersionID: "version"}, | ||
} | ||
ruleClientMock.On("Invoke", expectedInput, mock.Anything).Return(http.StatusOK, nil).Once() | ||
rule, err := cache.Get("id", "version") | ||
assert.NoError(t, err) | ||
assert.NotNil(t, rule) | ||
ruleClientMock.AssertExpectations(t) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.