Skip to content
This repository has been archived by the owner on Dec 11, 2024. It is now read-only.

Commit

Permalink
feat: verify minSize, minDigit, minSpecialChars and noRepeted
Browse files Browse the repository at this point in the history
  • Loading branch information
brandaogabriel7 committed Dec 19, 2022
1 parent f4a9293 commit 16e3028
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 28 deletions.
33 changes: 16 additions & 17 deletions graph/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion graph/model/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion graph/resolver.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package graph

import "github.com/brandaogabriel7/studio-sol-back-end-test/src/services/password_validation"

// This file will not be regenerated automatically.
//
// It serves as dependency injection for your app, add any dependencies you require here.

type Resolver struct{}
type Resolver struct{
PasswordValidationService password_validation.PasswordValidationService
}
2 changes: 1 addition & 1 deletion graph/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ type Verify {

input Rule {
rule: String!
value: Int
value: Int!
}

type Query {
Expand Down
3 changes: 2 additions & 1 deletion graph/schema.resolvers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions src/factories/password_validation_service_factory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package factories

import (
"github.com/brandaogabriel7/studio-sol-back-end-test/src/services/password_validation"
"github.com/brandaogabriel7/studio-sol-back-end-test/src/strategies/validation"
)

func GetDefaultPasswordValidationService() password_validation.PasswordValidationService {
validationStrategies := map[string]validation.ValidationStrategy{
string(validation.MIN_SIZE): validation.MinSizeValidationStrategy{},
string(validation.MIN_DIGIT): validation.NewMinDigitValidationStrategy(),
string(validation.MIN_SPECIAL_CHARS): validation.NewMinSpecialCharsValidationStrategy(),
string(validation.NO_REPETED): validation.NoRepetedStrategy{},
}

return *password_validation.NewPasswordValidationService(validationStrategies)
}
8 changes: 6 additions & 2 deletions src/integration_tests/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ import (
"github.com/99designs/gqlgen/graphql/handler"
"github.com/brandaogabriel7/studio-sol-back-end-test/graph"
"github.com/brandaogabriel7/studio-sol-back-end-test/graph/model"
"github.com/brandaogabriel7/studio-sol-back-end-test/src/factories"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

var _ = Describe("Verify", func() {
c := client.New(handler.NewDefaultServer(graph.NewExecutableSchema(graph.Config{Resolvers: &graph.Resolver{}})))
c := client.New(handler.NewDefaultServer(graph.NewExecutableSchema(graph.Config{
Resolvers: &graph.Resolver{
PasswordValidationService: factories.GetDefaultPasswordValidationService(),
}})))

Describe("Checking that password follows the specified rules", func () {
DescribeTable("minSize, minSpecialChars, noRepeted, minDigit",
Expand Down Expand Up @@ -81,7 +85,7 @@ var _ = Describe("Verify", func() {
Expect(resp.Verify.NoMatch).To(Equal(noMatch))
},
Entry("minSize", "0p@", 5, 1, 1, []string{"minSize"}),
Entry("minSize, minDigits, minSpecialChars", "SenhaForte!23", 20, 4, 2, []string{"minSize", "minDigits, minSpecialChars"}),
Entry("minSize, minSpecialChars, minDigit", "SenhaForte!2", 20, 4, 2, []string{"minSize", "minSpecialChars", "minDigit"}),
Entry("noRepeted", "aaaaaaa!2", 3, 1, 1, []string{"noRepeted"}),
)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (pvs *PasswordValidationService) Validate(password string, rules []*model.R
}
}
}
verifyResponse.Verify = len(verifyResponse.NoMatch) > 0
verifyResponse.Verify = len(verifyResponse.NoMatch) == 0

return verifyResponse
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ var _ = Describe("PasswordValidationService", func() {

verifyResponse := pvs.Validate(password, rules)

isValid := len(noMatch) > 0
isValid := len(noMatch) == 0

Expect(verifyResponse.NoMatch).To(Equal(noMatch))
Expect(verifyResponse.Verify).To(Equal(isValid))
},
Entry(
"third",
"opa",
[]model.Rule{
[]*model.Rule{
{Rule: FIRST_RULE, Value: 3},
{Rule: SECOND_RULE, Value: 2},
{Rule: THIRD_RULE, Value: 0},
Expand All @@ -72,7 +72,7 @@ var _ = Describe("PasswordValidationService", func() {
Entry(
"first, second",
"senhaaa",
[]model.Rule{
[]*model.Rule{
{Rule: FIRST_RULE, Value: 5},
{Rule: SECOND_RULE, Value: 7},
{Rule: THIRD_RULE, Value: 2},
Expand All @@ -82,7 +82,7 @@ var _ = Describe("PasswordValidationService", func() {
Entry(
"-",
"senhaforte",
[]model.Rule{
[]*model.Rule{
{Rule: FIRST_RULE, Value: 0},
{Rule: SECOND_RULE, Value: 7},
{Rule: THIRD_RULE, Value: 2},
Expand Down
8 changes: 8 additions & 0 deletions src/strategies/validation/validation_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package validation

type ValidationType string

const MIN_SIZE ValidationType = "minSize"
const MIN_DIGIT ValidationType = "minDigit"
const MIN_SPECIAL_CHARS ValidationType = "minSpecialChars"
const NO_REPETED ValidationType = "noRepeted"

0 comments on commit 16e3028

Please sign in to comment.