<commit_before>package authentication

import (
    "testing"
    "os"
    
	"github.com/SpectoLabs/hoverfly/authentication/backends"
)


// TestMain prepares database for testing and then performs a cleanup
func TestMain(m *testing.M) {
	setup()
	retCode := m.Run()
	// delete test database
	teardown()
	// call with result of m.Run()
	os.Exit(retCode)
}

func TestGenerateToken(t *testing.T) {
    ab := backends.NewBoltDBAuthBackend(TestDB, []byte(backends.TokenBucketName), []byte(backends.UserBucketName))
    jwtBackend := InitJWTAuthenticationBackend(ab, []byte("verysecret"), 100)
    
    token, err := jwtBackend.GenerateToken("userUUIDhereVeryLong", "userx")
    expect(t, err, nil)
    expect(t, len(token) > 0, true)
}

func TestAuthenticate(t *testing.T) {
    ab := backends.NewBoltDBAuthBackend(TestDB, []byte(backends.TokenBucketName), []byte(backends.UserBucketName))
    username := []byte("beloveduser")
    passw := []byte("<PASSWORD>")
    ab.AddUser(username, passw, true)
    
    jwtBackend := InitJWTAuthenticationBackend(ab, []byte("verysecret"), 100)
    user := &backends.User{
        Username: string(username), 
        Password: string(passw),
         UUID: "uuid_here",
        IsAdmin: true}
        
     success := jwtBackend.Authenticate(user)
     expect(t, success, true)
}<commit_msg>test auth fail<commit_after>package authentication

import (
    "testing"
    "os"
    
	"github.com/SpectoLabs/hoverfly/authentication/backends"
)


// TestMain prepares database for testing and then performs a cleanup
func TestMain(m *testing.M) {
	setup()
	retCode := m.Run()
	// delete test database
	teardown()
	// call with result of m.Run()
	os.Exit(retCode)
}

func TestGenerateToken(t *testing.T) {
    ab := backends.NewBoltDBAuthBackend(TestDB, []byte(backends.TokenBucketName), []byte(backends.UserBucketName))
    jwtBackend := InitJWTAuthenticationBackend(ab, []byte("verysecret"), 100)
    
    token, err := jwtBackend.GenerateToken("userUUIDhereVeryLong", "userx")
    expect(t, err, nil)
    expect(t, len(token) > 0, true)
}

func TestAuthenticate(t *testing.T) {
    ab := backends.NewBoltDBAuthBackend(TestDB, []byte(backends.TokenBucketName), []byte(backends.UserBucketName))
    username := []byte("beloveduser")
    passw := []byte("<PASSWORD>")
    ab.AddUser(username, passw, true)
    
    jwtBackend := InitJWTAuthenticationBackend(ab, []byte("verysecret"), 100)
    user := &backends.User{
        Username: string(username), 
        Password: string(<PASSWORD>),
         UUID: "uuid_here",
        IsAdmin: true}
        
     success := jwtBackend.Authenticate(user)
     expect(t, success, true)
}

func TestAuthenticateFail(t *testing.T) {
    ab := backends.NewBoltDBAuthBackend(TestDB, []byte(backends.TokenBucketName), GetRandomName(10))
    
    jwtBackend := InitJWTAuthenticationBackend(ab, []byte("verysecret"), 100)
    user := &backends.User{
        Username: "shouldntbehere", 
        Password: "<PASSWORD>",
         UUID: "uuid_here",
        IsAdmin: true}
        
     success := jwtBackend.Authenticate(user)
     expect(t, success, false)
}
{'fraction_non_alphanumeric': 0.13969881448253765, 'fraction_numerical': 0.006087792374239026, 'mean_word_length': 3.84031007751938, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5696231', 'n_tokens_mistral': 1048, 'n_tokens_neox': 1037, 'n_words': 202}