From 94ee66776091e3e4d4c871b2a66184ad9b4f5dd1 Mon Sep 17 00:00:00 2001 From: Krishna Upadhyay Date: Sat, 11 Jun 2022 19:36:37 +0545 Subject: [PATCH 1/4] Update the request for numverify scan --- lib/remote/suppliers/numverify.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/remote/suppliers/numverify.go b/lib/remote/suppliers/numverify.go index 7558165e4..0c7e4867a 100644 --- a/lib/remote/suppliers/numverify.go +++ b/lib/remote/suppliers/numverify.go @@ -4,9 +4,10 @@ import ( "encoding/json" "errors" "fmt" - "github.com/sirupsen/logrus" "net/http" "os" + + "github.com/sirupsen/logrus" ) type NumverifySupplierInterface interface { @@ -62,8 +63,16 @@ func (s *NumverifySupplier) Validate(internationalNumber string) (res *Numverify WithField("scheme", scheme). Debug("Running validate operation through Numverify API") + + url := fmt.Sprintf("%s://api.apilayer.com/number_verification/validate?number=%s", scheme, internationalNumber) + // Build the request - response, err := http.Get(fmt.Sprintf("%s://apilayer.net/api/validate?access_key=%s&number=%s", scheme, s.ApiKey, internationalNumber)) + client := &http.Client{} + req, _ := http.NewRequest("GET", url, nil) + req.Header.Set("apikey", s.ApiKey) + + response, err := client.Do(req) + if err != nil { return nil, err } From 4474f0094d1c4fb3052c1176f687de6edf725d33 Mon Sep 17 00:00:00 2001 From: Krishna Upadhyay Date: Thu, 16 Jun 2022 12:53:00 +0545 Subject: [PATCH 2/4] Update API endpoints in test files --- lib/remote/suppliers/numverify_test.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/remote/suppliers/numverify_test.go b/lib/remote/suppliers/numverify_test.go index 343a38cd3..6f83622d6 100644 --- a/lib/remote/suppliers/numverify_test.go +++ b/lib/remote/suppliers/numverify_test.go @@ -32,9 +32,9 @@ func TestNumverifySupplierSuccess(t *testing.T) { LineType: "mobile", } - gock.New("https://apilayer.net"). - Get("/api/validate"). - MatchParam("access_key", "5ad5554ac240e4d3d31107941b35a5eb"). + gock.New("https://api.apilayer.com"). + Get("/number_verification/validate"). + MatchHeader("apikey", "5ad5554ac240e4d3d31107941b35a5eb"). MatchParam("number", number). Reply(200). JSON(expectedResult) @@ -70,9 +70,9 @@ func TestNumverifySupplierWithoutSSL(t *testing.T) { LineType: "mobile", } - gock.New("http://apilayer.net"). - Get("/api/validate"). - MatchParam("access_key", "5ad5554ac240e4d3d31107941b35a5eb"). + gock.New("http://api.apilayer.com"). + Get("/number_verification/validate"). + MatchHeader("apikey", "5ad5554ac240e4d3d31107941b35a5eb"). MatchParam("number", number). Reply(200). JSON(expectedResult) @@ -103,9 +103,9 @@ func TestNumverifySupplierError(t *testing.T) { }, } - gock.New("http://apilayer.net"). - Get("/api/validate"). - MatchParam("access_key", "5ad5554ac240e4d3d31107941b35a5eb"). + gock.New("http://api.apilayer.com"). + Get("/number_verification/validate"). + MatchHeader("apikey", "5ad5554ac240e4d3d31107941b35a5eb"). MatchParam("number", number). Reply(400). JSON(expectedResult) @@ -131,8 +131,8 @@ func TestNumverifySupplierHTTPError(t *testing.T) { dummyError := errors.New("test") - gock.New("https://apilayer.net"). - Get("/api/validate"). + gock.New("https://api.apilayer.com"). + Get("/number_verification/validate"). ReplyError(dummyError) s := NewNumverifySupplier() @@ -143,7 +143,7 @@ func TestNumverifySupplierHTTPError(t *testing.T) { assert.Nil(t, got) assert.Equal(t, &url.Error{ Op: "Get", - URL: "https://apilayer.net/api/validate?access_key=5ad5554ac240e4d3d31107941b35a5eb&number=11115551212", + URL: "https://api.apilayer.com/number_verification/validate?&number=11115551212", Err: dummyError, }, err) } From 21b6129dc9080b9b94013ef716d810661bb3e4eb Mon Sep 17 00:00:00 2001 From: Krishna Upadhyay Date: Thu, 16 Jun 2022 13:45:20 +0545 Subject: [PATCH 3/4] Fix the extra ampersand symbol --- lib/remote/suppliers/numverify_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/remote/suppliers/numverify_test.go b/lib/remote/suppliers/numverify_test.go index 6f83622d6..5c72a37a2 100644 --- a/lib/remote/suppliers/numverify_test.go +++ b/lib/remote/suppliers/numverify_test.go @@ -143,7 +143,7 @@ func TestNumverifySupplierHTTPError(t *testing.T) { assert.Nil(t, got) assert.Equal(t, &url.Error{ Op: "Get", - URL: "https://api.apilayer.com/number_verification/validate?&number=11115551212", + URL: "https://api.apilayer.com/number_verification/validate?number=11115551212", Err: dummyError, }, err) } From f3f280e02d4e4e4e8b01fa6ef3c4d3dcaf7b6fc6 Mon Sep 17 00:00:00 2001 From: Krishna Upadhyay Date: Sun, 19 Jun 2022 16:02:12 +0545 Subject: [PATCH 4/4] Update server api mock and change the Header case --- api/server_test.go | 6 +++--- lib/remote/suppliers/numverify.go | 2 +- lib/remote/suppliers/numverify_test.go | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/api/server_test.go b/api/server_test.go index b51fc711e..843745f7b 100644 --- a/api/server_test.go +++ b/api/server_test.go @@ -141,9 +141,9 @@ func TestApi(t *testing.T) { LineType: "mobile", } - gock.New("http://apilayer.net"). - Get("/api/validate"). - MatchParam("access_key", "5ad5554ac240e4d3d31107941b35a5eb"). + gock.New("http://api.apilayer.com"). + Get("/number_verification/validate"). + MatchHeader("Apikey", "5ad5554ac240e4d3d31107941b35a5eb"). MatchParam("number", number). Reply(200). JSON(expectedResult) diff --git a/lib/remote/suppliers/numverify.go b/lib/remote/suppliers/numverify.go index 0c7e4867a..f91fc72f7 100644 --- a/lib/remote/suppliers/numverify.go +++ b/lib/remote/suppliers/numverify.go @@ -69,7 +69,7 @@ func (s *NumverifySupplier) Validate(internationalNumber string) (res *Numverify // Build the request client := &http.Client{} req, _ := http.NewRequest("GET", url, nil) - req.Header.Set("apikey", s.ApiKey) + req.Header.Set("Apikey", s.ApiKey) response, err := client.Do(req) diff --git a/lib/remote/suppliers/numverify_test.go b/lib/remote/suppliers/numverify_test.go index 5c72a37a2..94422b829 100644 --- a/lib/remote/suppliers/numverify_test.go +++ b/lib/remote/suppliers/numverify_test.go @@ -34,7 +34,7 @@ func TestNumverifySupplierSuccess(t *testing.T) { gock.New("https://api.apilayer.com"). Get("/number_verification/validate"). - MatchHeader("apikey", "5ad5554ac240e4d3d31107941b35a5eb"). + MatchHeader("Apikey", "5ad5554ac240e4d3d31107941b35a5eb"). MatchParam("number", number). Reply(200). JSON(expectedResult) @@ -72,7 +72,7 @@ func TestNumverifySupplierWithoutSSL(t *testing.T) { gock.New("http://api.apilayer.com"). Get("/number_verification/validate"). - MatchHeader("apikey", "5ad5554ac240e4d3d31107941b35a5eb"). + MatchHeader("Apikey", "5ad5554ac240e4d3d31107941b35a5eb"). MatchParam("number", number). Reply(200). JSON(expectedResult) @@ -105,7 +105,7 @@ func TestNumverifySupplierError(t *testing.T) { gock.New("http://api.apilayer.com"). Get("/number_verification/validate"). - MatchHeader("apikey", "5ad5554ac240e4d3d31107941b35a5eb"). + MatchHeader("Apikey", "5ad5554ac240e4d3d31107941b35a5eb"). MatchParam("number", number). Reply(400). JSON(expectedResult)