add simply e2e/integration tests
This commit is contained in:
parent
58601b63bb
commit
69dc99e50b
@ -23,7 +23,7 @@ func main() {
|
||||
log.Fatal("Error parsing build time:", zap.Error(err))
|
||||
}
|
||||
|
||||
cfg, err := config.NewConfig("././test.env")
|
||||
cfg, err := config.NewConfig("staging.env")
|
||||
if err != nil {
|
||||
log.Fatal("can't load config: ", err.Error())
|
||||
}
|
||||
|
2
go.mod
2
go.mod
@ -14,7 +14,7 @@ require (
|
||||
github.com/themakers/hlog v0.0.0-20191205140925-235e0e4baddf
|
||||
go.mongodb.org/mongo-driver v1.14.0
|
||||
go.uber.org/zap v1.27.0
|
||||
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240223054633-6cb3d5ce45b6
|
||||
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240527160654-bd1c2126bc6c
|
||||
penahub.gitlab.yandexcloud.net/external/trashlog.git v0.1.2-0.20240523172059-9bbe8a9faa31
|
||||
penahub.gitlab.yandexcloud.net/pena-services/customer v1.0.1-0.20240526134522-aab18dfcec46
|
||||
)
|
||||
|
4
go.sum
4
go.sum
@ -241,6 +241,10 @@ gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
||||
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240223054633-6cb3d5ce45b6 h1:oV+/HNX+JPoQ3/GUx08hio7d45WpY0AMGrFs7j70QlA=
|
||||
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240223054633-6cb3d5ce45b6/go.mod h1:lTmpjry+8evVkXWbEC+WMOELcFkRD1lFMc7J09mOndM=
|
||||
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240527155320-a234eec54383 h1:B6nHWxqx3YD84nHm6/TgTvaG1sRfGGOVv6tdaqJkTQ4=
|
||||
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240527155320-a234eec54383/go.mod h1:lTmpjry+8evVkXWbEC+WMOELcFkRD1lFMc7J09mOndM=
|
||||
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240527160654-bd1c2126bc6c h1:jxnyIeC2CNDNmfdFx2qnLS4Qd0v5ocYrY9X+OL9qsvc=
|
||||
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240527160654-bd1c2126bc6c/go.mod h1:lTmpjry+8evVkXWbEC+WMOELcFkRD1lFMc7J09mOndM=
|
||||
penahub.gitlab.yandexcloud.net/external/trashlog.git v0.1.2-0.20240523172059-9bbe8a9faa31 h1:WlRVJnzU0sti+qBq/JTCgFPU0RoxIqGHu7hzDirxE2k=
|
||||
penahub.gitlab.yandexcloud.net/external/trashlog.git v0.1.2-0.20240523172059-9bbe8a9faa31/go.mod h1:3ml0dAGT8U8RhpevKBfRgG6yKZum8EI2uJxAb2WCIy4=
|
||||
penahub.gitlab.yandexcloud.net/pena-services/customer v1.0.1-0.20240526134522-aab18dfcec46 h1:AX5HxEjjOf6YajMmi2vAB8hErBGEGouPB8ei9VVmdmo=
|
||||
|
BIN
recover.bolt
BIN
recover.bolt
Binary file not shown.
61
tests/e2e/create_verify_user_test.go
Normal file
61
tests/e2e/create_verify_user_test.go
Normal file
@ -0,0 +1,61 @@
|
||||
package e2e
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"io"
|
||||
"mime/multipart"
|
||||
"os"
|
||||
"penahub.gitlab.yandexcloud.net/backend/verification/tests/helpers"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_SetVerify(t *testing.T) {
|
||||
url := "http://localhost:8080/verification"
|
||||
client := fiber.AcquireClient()
|
||||
|
||||
token, err := helpers.CreateJwt("64e53ed187392e122e5d3d50")
|
||||
assert.NoError(t, err)
|
||||
|
||||
fmt.Println(token)
|
||||
|
||||
assert.NoError(t, err)
|
||||
|
||||
var requestBody bytes.Buffer
|
||||
writer := multipart.NewWriter(&requestBody)
|
||||
err = writer.WriteField("status", "nko")
|
||||
assert.NoError(t, err)
|
||||
files := []struct {
|
||||
fieldName string
|
||||
filePath string
|
||||
}{
|
||||
{"inn", "files/inn"},
|
||||
{"rule", "files/rule"},
|
||||
{"egrule", "files/egrule"},
|
||||
{"certificate", "files/certificate"},
|
||||
}
|
||||
for _, file := range files {
|
||||
fileWriter, err := writer.CreateFormFile(file.fieldName, file.filePath)
|
||||
assert.NoError(t, err)
|
||||
|
||||
f, err := os.Open(file.filePath)
|
||||
assert.NoError(t, err)
|
||||
defer f.Close()
|
||||
_, err = io.Copy(fileWriter, f)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
writer.Close()
|
||||
|
||||
agent := client.Post(url).Body(requestBody.Bytes()).ContentType(writer.FormDataContentType())
|
||||
agent.Set("Authorization", fmt.Sprintf("Bearer %s", token))
|
||||
statusCode, respBody, errs := agent.Bytes()
|
||||
if len(errs) > 0 {
|
||||
assert.NoError(t, errs[0])
|
||||
}
|
||||
assert.Equal(t, 200, statusCode)
|
||||
|
||||
fmt.Println(string(respBody))
|
||||
}
|
1
tests/e2e/files/certificate
Normal file
1
tests/e2e/files/certificate
Normal file
@ -0,0 +1 @@
|
||||
аываывавыфавыавыфаываываываывпыпыфывиываолиыврмиыврмиывимролыиф
|
1
tests/e2e/files/egrule
Normal file
1
tests/e2e/files/egrule
Normal file
@ -0,0 +1 @@
|
||||
аываывавыфавыавыфаываываываывпыпыфывиываолиыврмиыврмиывимролыиф
|
1
tests/e2e/files/inn
Normal file
1
tests/e2e/files/inn
Normal file
@ -0,0 +1 @@
|
||||
аываывавыфавыавыфаываываываывпыпыфывиываолиыврмиыврмиывимролыиф
|
1
tests/e2e/files/rule
Normal file
1
tests/e2e/files/rule
Normal file
@ -0,0 +1 @@
|
||||
аываывавыфавыавыфаываываываывпыпыфывиываолиыврмиыврмиывимролыиф
|
57
tests/e2e/get_verify_admin_test.go
Normal file
57
tests/e2e/get_verify_admin_test.go
Normal file
@ -0,0 +1,57 @@
|
||||
package e2e
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"penahub.gitlab.yandexcloud.net/backend/verification/internal/models"
|
||||
"penahub.gitlab.yandexcloud.net/backend/verification/tests/helpers"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_GetVerifyAdmin(t *testing.T) {
|
||||
url := "http://localhost:8080/verification/64e53ed187392e122e5d3d50"
|
||||
client := fiber.AcquireClient()
|
||||
|
||||
token, err := helpers.CreateJwt("64e53ed187392e122e5d3d51")
|
||||
assert.NoError(t, err)
|
||||
|
||||
agent := client.Get(url)
|
||||
agent.Set("Authorization", fmt.Sprintf("Bearer %s", token))
|
||||
|
||||
statusCode, respBody, errs := agent.Bytes()
|
||||
if len(errs) > 0 {
|
||||
assert.NoError(t, errs[0])
|
||||
}
|
||||
assert.Equal(t, 200, statusCode)
|
||||
|
||||
var resp models.Verification
|
||||
err = json.Unmarshal(respBody, &resp)
|
||||
assert.NoError(t, err)
|
||||
fmt.Println(resp)
|
||||
|
||||
url = "http://localhost:8080/verification"
|
||||
client2 := fiber.AcquireClient()
|
||||
|
||||
req := models.ReqSetVerification{
|
||||
ID: resp.ID,
|
||||
Status: "nko",
|
||||
Comment: "MOLODEC, GOOD JOB",
|
||||
Accepted: true,
|
||||
TaxNumber: "000-000-000",
|
||||
}
|
||||
|
||||
reqBody, err := json.Marshal(req)
|
||||
assert.NoError(t, err)
|
||||
|
||||
agent2 := client2.Patch(url).Body(reqBody).ContentType("application/json")
|
||||
agent2.Set("Authorization", fmt.Sprintf("Bearer %s", token))
|
||||
|
||||
statusCode, _, errs = agent2.Bytes()
|
||||
if len(errs) > 0 {
|
||||
fmt.Println(errs[0])
|
||||
assert.NoError(t, errs[0])
|
||||
}
|
||||
assert.Equal(t, 200, statusCode)
|
||||
}
|
33
tests/e2e/get_verify_user_test.go
Normal file
33
tests/e2e/get_verify_user_test.go
Normal file
@ -0,0 +1,33 @@
|
||||
package e2e
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"penahub.gitlab.yandexcloud.net/backend/verification/internal/models"
|
||||
"penahub.gitlab.yandexcloud.net/backend/verification/tests/helpers"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_Get_Verify_User(t *testing.T) {
|
||||
url := "http://localhost:8080/verification"
|
||||
client := fiber.AcquireClient()
|
||||
|
||||
token, err := helpers.CreateJwt("64e53ed187392e122e5d3d50")
|
||||
assert.NoError(t, err)
|
||||
|
||||
agent := client.Get(url)
|
||||
agent.Set("Authorization", fmt.Sprintf("Bearer %s", token))
|
||||
|
||||
statusCode, respBody, errs := agent.Bytes()
|
||||
if len(errs) > 0 {
|
||||
assert.NoError(t, errs[0])
|
||||
}
|
||||
assert.Equal(t, 200, statusCode)
|
||||
|
||||
var resp models.Verification
|
||||
err = json.Unmarshal(respBody, &resp)
|
||||
assert.NoError(t, err)
|
||||
fmt.Println(resp)
|
||||
}
|
60
tests/e2e/set_verify_file_user_test.go
Normal file
60
tests/e2e/set_verify_file_user_test.go
Normal file
@ -0,0 +1,60 @@
|
||||
package e2e
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"io"
|
||||
"mime/multipart"
|
||||
"os"
|
||||
"penahub.gitlab.yandexcloud.net/backend/verification/tests/helpers"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_PutFile(t *testing.T) {
|
||||
url := "http://localhost:8080/verification"
|
||||
client := fiber.AcquireClient()
|
||||
|
||||
token, err := helpers.CreateJwt("64e53ed187392e122e5d3d51")
|
||||
assert.NoError(t, err)
|
||||
|
||||
fmt.Println(token)
|
||||
|
||||
assert.NoError(t, err)
|
||||
|
||||
var requestBody bytes.Buffer
|
||||
writer := multipart.NewWriter(&requestBody)
|
||||
|
||||
files := []struct {
|
||||
fieldName string
|
||||
filePath string
|
||||
}{
|
||||
{"inn", "files/inn"},
|
||||
{"rule", "files/rule"},
|
||||
{"egrule", "files/egrule"},
|
||||
{"certificate", "files/certificate"},
|
||||
}
|
||||
for _, file := range files {
|
||||
fileWriter, err := writer.CreateFormFile(file.fieldName, file.filePath)
|
||||
assert.NoError(t, err)
|
||||
|
||||
f, err := os.Open(file.filePath)
|
||||
assert.NoError(t, err)
|
||||
defer f.Close()
|
||||
_, err = io.Copy(fileWriter, f)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
writer.Close()
|
||||
|
||||
agent := client.Put(url).Body(requestBody.Bytes()).ContentType(writer.FormDataContentType())
|
||||
agent.Set("Authorization", fmt.Sprintf("Bearer %s", token))
|
||||
statusCode, respBody, errs := agent.Bytes()
|
||||
if len(errs) > 0 {
|
||||
assert.NoError(t, errs[0])
|
||||
}
|
||||
assert.Equal(t, 200, statusCode)
|
||||
|
||||
fmt.Println(string(respBody))
|
||||
}
|
43
tests/helpers/jwt.go
Normal file
43
tests/helpers/jwt.go
Normal file
@ -0,0 +1,43 @@
|
||||
package helpers
|
||||
|
||||
import (
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
"penahub.gitlab.yandexcloud.net/backend/penahub_common/jwt_adapter"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func CreateJwt(userID string) (string, error) {
|
||||
var publicKey = strings.Replace(`-----BEGIN PUBLIC KEY-----
|
||||
MIGeMA0GCSqGSIb3DQEBAQUAA4GMADCBiAKBgHgnvr7O2tiApjJfid1orFnIGm69
|
||||
80fZp+Lpbjo+NC/0whMFga2Biw5b1G2Q/B2u0tpO1Fs/E8z7Lv1nYfr5jx2S8x6B
|
||||
dA4TS2kB9Kf0wn0+7wSlyikHoKhbtzwXHZl17GsyEi6wHnsqNBSauyIWhpha8i+Y
|
||||
+3GyaOY536H47qyXAgMBAAE=
|
||||
-----END PUBLIC KEY-----`, "\t", "", -1)
|
||||
|
||||
var privateKey = strings.Replace(`-----BEGIN RSA PRIVATE KEY-----
|
||||
MIICWwIBAAKBgHgnvr7O2tiApjJfid1orFnIGm6980fZp+Lpbjo+NC/0whMFga2B
|
||||
iw5b1G2Q/B2u0tpO1Fs/E8z7Lv1nYfr5jx2S8x6BdA4TS2kB9Kf0wn0+7wSlyikH
|
||||
oKhbtzwXHZl17GsyEi6wHnsqNBSauyIWhpha8i+Y+3GyaOY536H47qyXAgMBAAEC
|
||||
gYAOphnVPXbk6lpYzdkLC1Xn5EOEuNfOLLURLxBnPWozZo26r/Mtahu/9mYhrYlv
|
||||
PP8r6mxta3VIil8iOdZyOLa/4d1LPd+UehgEXIJEiYXLtn7RS5eUnoPuQxssfs1k
|
||||
OWjdN8p6SzppleegFTvGRX4KM3cDLfSphOk8JuBCrpSSYQJBAOdqizTSrdKMTuVe
|
||||
c7Jk1JOJkyFuFs+N5zeryyeFGH7IpRdWy0rkWMxIUAi8Ap1vYVBPHv4tDOo3sy5X
|
||||
VLc/knkCQQCE62pg+0TmsrhO/2Pgog6MLBkzlzXYMRp/01HbmznwYF+ejfPnzLkz
|
||||
hnUlxRUNK3lhXM/7H6oAjvqF2R72u/OPAkEAterkmdbQfEZ+MwNoEiH/lie9OLdx
|
||||
SSI1VGdBYcTYN7qFRW6eizYstBJYkDU0HQ0Uw+we4hMKJwk4W0KdvxxDiQJAeqlB
|
||||
V1QqBneBbK10PzVuFV8QtrJhJyxRVwrtbKq38iMNuqUnI4+ijXEUpJFWVvv6nKXo
|
||||
7McQvEk12dU/JNTX8wJAOlAtSNjp9tVwpMpC0w2St1eKc1L2SknjeohA5ldoBz8sGeZsPhTU3eHSD1neAZXLKN5K68z3zFBr20ubY9nyLw==
|
||||
-----END RSA PRIVATE KEY-----`, "\t", "", -1)
|
||||
|
||||
token, err := jwt_adapter.Create(userID, jwt_adapter.ForCreate{
|
||||
PrivateKey: []byte(privateKey),
|
||||
PublicKey: []byte(publicKey),
|
||||
Audience: "pena",
|
||||
Issuer: "pena-auth-service",
|
||||
Algorithm: jwt.SigningMethodRS256,
|
||||
ExpiresIn: 15 * time.Minute,
|
||||
})
|
||||
|
||||
return token, err
|
||||
}
|
Loading…
Reference in New Issue
Block a user