You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
bathyscaphe/internal/constraint/hostname_test.go

30 lines
877 B
Go

package constraint
import (
"github.com/darkspot-org/bathyscaphe/internal/configapi/client"
"github.com/darkspot-org/bathyscaphe/internal/configapi/client_mock"
"github.com/golang/mock/gomock"
"testing"
)
func TestCheckHostnameAllowed(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
configClientMock := client_mock.NewMockClient(mockCtrl)
configClientMock.EXPECT().GetForbiddenHostnames().Return([]client.ForbiddenHostname{
{Hostname: "google.onion"},
}, nil)
if allowed, err := CheckHostnameAllowed(configClientMock, "https://google.onion"); allowed || err != nil {
t.Fail()
}
configClientMock.EXPECT().GetForbiddenHostnames().Return([]client.ForbiddenHostname{
{Hostname: "google.onion"},
}, nil)
if allowed, err := CheckHostnameAllowed(configClientMock, "https://google2.onion"); !allowed || err != nil {
t.Fail()
}
}