package security_test

import (
	"testing"

	"github.com/fiskerinc/cloud-services/pkg/redis"
	"github.com/fiskerinc/cloud-services/pkg/security"
	"github.com/fiskerinc/cloud-services/pkg/testhelper"
)

func TestSalter(t *testing.T) {
	redis.MockRedisConnection()
	mockRedis := &redis.Connection{}

	var salter security.ISalter
	vin := "VALIDVIN123"

	salter, err := security.NewSalter(vin)
	if err != nil {
		t.Errorf(testhelper.TestErrorTemplate, "TestSalter", nil, err)
		return
	}

	sessionID := salter.GenerateSessionID(vin, "SALT")
	if sessionID == "" {
		t.Errorf(testhelper.TestErrorTemplate, "TestSalter", "", sessionID)
		return
	}

	err = salter.ValidateSessionID(sessionID)
	if err != nil {
		t.Errorf(testhelper.TestErrorTemplate, "TestSalter", nil, err)
		return
	}

	err = salter.ValidateSessionID("INVALIDSESSIONID")
	if err == nil {
		t.Errorf(testhelper.TestErrorTemplate, "TestSalter", "error", err)
		return
	}

	err = salter.ValidateSessionID("")
	if err == nil {
		t.Errorf(testhelper.TestErrorTemplate, "TestSalter", "error", err)
		return
	}

	err = salter.CheckSessionID(mockRedis, "Vin")
	if err == nil {
		t.Errorf(testhelper.TestErrorTemplate, "TestSalter", "error", err)
		return
	}
}
