Skip to content

Commit

Permalink
Merge pull request #286 from OFFLINE-GmbH/move-url-validation
Browse files Browse the repository at this point in the history
Changed url validation
  • Loading branch information
thrawn01 authored May 23, 2022
2 parents f4d95ac + 5d7b293 commit acda9bf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion httphelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"strings"
)

var validURL = regexp.MustCompile(`^/v[2-4].*`)
var validURL = regexp.MustCompile(`/v[2-4].*`)

type httpRequest struct {
URL string
Expand Down
27 changes: 27 additions & 0 deletions mailgun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package mailgun_test

import (
"context"
"encoding/json"
"fmt"
"net/http"
"net/http/httptest"
"testing"

"github.com/facebookgo/ensure"
Expand Down Expand Up @@ -33,3 +36,27 @@ func TestInvalidBaseAPI(t *testing.T) {
ensure.NotNil(t, err)
ensure.DeepEqual(t, err.Error(), `BaseAPI must end with a /v2, /v3 or /v4; setBaseAPI("https://host/v3")`)
}

func TestValidBaseAPI(t *testing.T) {
testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var resp mailgun.DomainResponse
b, err := json.Marshal(resp)
ensure.Nil(t, err)

w.Write(b)
}))

apiBases := []string{
fmt.Sprintf("%s/v3", testServer.URL),
fmt.Sprintf("%s/proxy/v3", testServer.URL),
}

for _, apiBase := range apiBases {
mg := mailgun.NewMailgun(testDomain, testKey)
mg.SetAPIBase(apiBase)

ctx := context.Background()
_, err := mg.GetDomain(ctx, "unknown.domain")
ensure.Nil(t, err)
}
}

0 comments on commit acda9bf

Please sign in to comment.