2021-12-22 10:01:45 +00:00
package test
import (
"testing"
"github.com/authorizerdev/authorizer/server/constants"
2022-05-30 03:49:55 +00:00
"github.com/authorizerdev/authorizer/server/memorystore"
2021-12-22 10:01:45 +00:00
"github.com/authorizerdev/authorizer/server/utils"
2022-05-30 06:24:16 +00:00
"github.com/authorizerdev/authorizer/server/validators"
2021-12-22 10:01:45 +00:00
"github.com/stretchr/testify/assert"
)
func TestIsValidEmail ( t * testing . T ) {
validEmail := "lakhan@gmail.com"
invalidEmail1 := "lakhan"
invalidEmail2 := "lakhan.me"
2022-05-30 06:24:16 +00:00
assert . True ( t , validators . IsValidEmail ( validEmail ) , "it should be valid email" )
assert . False ( t , validators . IsValidEmail ( invalidEmail1 ) , "it should be invalid email" )
assert . False ( t , validators . IsValidEmail ( invalidEmail2 ) , "it should be invalid email" )
2021-12-22 10:01:45 +00:00
}
func TestIsValidOrigin ( t * testing . T ) {
// don't use portocal(http/https) for ALLOWED_ORIGINS while testing,
// as we trim them off while running the main function
2022-05-30 03:49:55 +00:00
memorystore . Provider . UpdateEnvVariable ( constants . SliceStoreIdentifier , constants . EnvKeyAllowedOrigins , [ ] string { "localhost:8080" , "*.google.com" , "*.google.in" , "*abc.*" } )
2022-05-30 06:24:16 +00:00
assert . False ( t , validators . IsValidOrigin ( "http://myapp.com" ) , "it should be invalid origin" )
assert . False ( t , validators . IsValidOrigin ( "http://appgoogle.com" ) , "it should be invalid origin" )
assert . True ( t , validators . IsValidOrigin ( "http://app.google.com" ) , "it should be valid origin" )
assert . False ( t , validators . IsValidOrigin ( "http://app.google.ind" ) , "it should be invalid origin" )
assert . True ( t , validators . IsValidOrigin ( "http://app.google.in" ) , "it should be valid origin" )
assert . True ( t , validators . IsValidOrigin ( "http://xyx.abc.com" ) , "it should be valid origin" )
assert . True ( t , validators . IsValidOrigin ( "http://xyx.abc.in" ) , "it should be valid origin" )
assert . True ( t , validators . IsValidOrigin ( "http://xyxabc.in" ) , "it should be valid origin" )
assert . True ( t , validators . IsValidOrigin ( "http://localhost:8080" ) , "it should be valid origin" )
2022-05-30 03:49:55 +00:00
memorystore . Provider . UpdateEnvVariable ( constants . SliceStoreIdentifier , constants . EnvKeyAllowedOrigins , [ ] string { "*" } )
2021-12-22 10:01:45 +00:00
}
2021-12-23 05:01:52 +00:00
func TestIsValidIdentifier ( t * testing . T ) {
assert . False ( t , utils . IsValidVerificationIdentifier ( "test" ) , "it should be invalid identifier" )
2022-01-17 06:02:13 +00:00
assert . True ( t , utils . IsValidVerificationIdentifier ( constants . VerificationTypeBasicAuthSignup ) , "it should be valid identifier" )
assert . True ( t , utils . IsValidVerificationIdentifier ( constants . VerificationTypeUpdateEmail ) , "it should be valid identifier" )
assert . True ( t , utils . IsValidVerificationIdentifier ( constants . VerificationTypeForgotPassword ) , "it should be valid identifier" )
2021-12-23 05:01:52 +00:00
}
2022-03-17 10:05:07 +00:00
func TestIsValidPassword ( t * testing . T ) {
assert . False ( t , utils . IsValidPassword ( "test" ) , "it should be invalid password" )
assert . False ( t , utils . IsValidPassword ( "Te@1" ) , "it should be invalid password" )
assert . False ( t , utils . IsValidPassword ( "n*rp7GGTd29V{xx%{pDb@7n{](SD.!+.Mp#*$EHDGk&$pAMf7e#432Sg,Gr](j3n]jV/3F8BJJT+9u9{q=8zK:8u!rpQBaXJp%A+7r!jQj)M(vC$UX,h;;WKm$U6i#7dBnC&2ryKzKd+(y&=Ud)hErT/j;v3t..CM).8nS)9qLtV7pmP;@2QuzDyGfL7KB()k:BpjAGL@bxD%r5gcBfh7$&wutk!wzMfPFY#nkjjqyZbEHku,{jc;gvbYq2)3w=KExnYz9Vbv:;*;?f##faxkULdMpmm&yEfePixzx+[{[38zGN;3TzF;6M#Xy_tMtx:yK*n$bc(bPyGz%EYkC&]ttUF@#aZ%$QZ:u!icF@+" ) , "it should be invalid password" )
assert . False ( t , utils . IsValidPassword ( "test@123" ) , "it should be invalid password" )
assert . True ( t , utils . IsValidPassword ( "Test@123" ) , "it should be valid password" )
}