Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/checkin/escrow.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,10 @@ func buildCheckinURL(p pref.PrefInterface) (string, error) {
if err != nil {
return "", errors.Wrap(err, "failed to get server URL")
}
if strings.HasSuffix(serverURL, "/default") {
serverURL = serverURL + "/checkin"
return serverURL, nil
}
if !strings.HasSuffix(serverURL, "/") {
serverURL = serverURL + "/"
}
Expand Down
59 changes: 59 additions & 0 deletions pkg/checkin/escrow_mock_helper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package checkin

type MockPrefV2 struct {
ServerURL string
}

func (m *MockPrefV2) GetString(key string) (string, error) {
return m.ServerURL, nil
}

func (m *MockPrefV2) SetString(key string, value string) error {
m.ServerURL = value
return nil
}

func (m *MockPrefV2) GetInt(key string) (int, error) {
// not implemented yet. Just to satisty interface
return 0, nil
}

func (m *MockPrefV2) SetInt(key string, value int) error {
// not implemented yet. Just to satisty interface
return nil
}

func (m *MockPrefV2) GetArray(key string) ([]string, error) {
// not implemented yet. Just to satisty interface
return nil, nil
}

func (m *MockPrefV2) SetArray(key string, value []string) error {
// not implemented yet. Just to satisty interface
return nil
}

func (m *MockPrefV2) Get(key string) (interface{}, error) {
// not implemented yet. Just to satisty interface
return nil, nil
}

func (m *MockPrefV2) Set(key string, value interface{}) error {
// not implemented yet. Just to satisty interface
return nil
}

func (m *MockPrefV2) Delete(key string) error {
// not implemented yet. Just to satisty interface
return nil
}

func (m *MockPrefV2) GetBool(key string) (bool, error) {
// not implemented yet. Just to satisty interface
return false, nil
}

func (m *MockPrefV2) SetBool(key string, value bool) error {
// not implemented yet. Just to satisty interface
return nil
}
26 changes: 26 additions & 0 deletions pkg/checkin/escrow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ func (m *MockPref) GetString(key string) (string, error) {
return "", nil
}

func newMockPref(ServerURL string) *MockPrefV2 {
m := &MockPrefV2{}

m.ServerURL = ServerURL

return m
}

func (m *MockPref) SetString(key string, value string) error {
return nil
}
Expand Down Expand Up @@ -97,6 +105,24 @@ func TestBuildCheckinURL(t *testing.T) {

}

func TestBuildNonTrailingSlashURL(t *testing.T) {
p := newMockPref("http://test.com/default")

url, err := buildCheckinURL(p)
assert.Nil(t, err)
assert.Equal(t, "http://test.com/default/checkin", url)

}

func TestHandleNonDefaultURL(t *testing.T) {
p := newMockPref("http://test.com/-default")

url, err := buildCheckinURL(p)
assert.Nil(t, err)
assert.Equal(t, "http://test.com/-default/checkin/", url)

}

func TestEscrowRequired(t *testing.T) {
cryptData := CryptData{
LastRun: time.Date(2022, time.January, 1, 0, 0, 0, 0, time.UTC),
Expand Down
Loading