Increase pro quota and bodysize

This commit is contained in:
Mike Schwörer 2023-07-30 16:37:39 +02:00
parent 165c6d8614
commit ee9e858584
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
5 changed files with 33 additions and 47 deletions

View File

@ -165,14 +165,6 @@ func (app *Application) GenerateRandomAuthKey() string {
return scn.RandomAuthKey() return scn.RandomAuthKey()
} }
func (app *Application) QuotaMax(ispro bool) int {
if ispro {
return 1000
} else {
return 50
}
}
func (app *Application) VerifyProToken(ctx *AppContext, token string) (bool, error) { func (app *Application) VerifyProToken(ctx *AppContext, token string) (bool, error) {
if strings.HasPrefix(token, "ANDROID|v1|") { if strings.HasPrefix(token, "ANDROID|v1|") {

View File

@ -49,9 +49,9 @@ func (u User) JSONWithClients(clients []Client, ak string, sk string, rk string)
func (u User) MaxContentLength() int { func (u User) MaxContentLength() int {
if u.IsPro { if u.IsPro {
return 16384 return 2 * 1024 * 1024 // 2 MB
} else { } else {
return 2048 return 2 * 1024 // 2 KB
} }
} }
@ -61,7 +61,7 @@ func (u User) MaxTitleLength() int {
func (u User) QuotaPerDay() int { func (u User) QuotaPerDay() int {
if u.IsPro { if u.IsPro {
return 1000 return 5000
} else { } else {
return 50 return 50
} }

View File

@ -321,7 +321,7 @@ func TestCompatRegisterPro(t *testing.T) {
tt.AssertEqual(t, "success", true, r0["success"]) tt.AssertEqual(t, "success", true, r0["success"])
tt.AssertEqual(t, "message", "New user registered", r0["message"]) tt.AssertEqual(t, "message", "New user registered", r0["message"])
tt.AssertEqual(t, "quota", 0, r0["quota"]) tt.AssertEqual(t, "quota", 0, r0["quota"])
tt.AssertEqual(t, "quota_max", 1000, r0["quota_max"]) tt.AssertEqual(t, "quota_max", 5000, r0["quota_max"])
tt.AssertEqual(t, "is_pro", true, r0["is_pro"]) tt.AssertEqual(t, "is_pro", true, r0["is_pro"])
r1 := tt.RequestGet[gin.H](t, baseUrl, fmt.Sprintf("/api/register.php?fcm_token=%s&pro=%s&pro_token=%s", "DUMMY_FCM", "true", url.QueryEscape("INVALID"))) r1 := tt.RequestGet[gin.H](t, baseUrl, fmt.Sprintf("/api/register.php?fcm_token=%s&pro=%s&pro_token=%s", "DUMMY_FCM", "true", url.QueryEscape("INVALID")))
@ -555,7 +555,7 @@ func TestCompatUpgrade(t *testing.T) {
tt.AssertEqual(t, "success", true, r1["success"]) tt.AssertEqual(t, "success", true, r1["success"])
tt.AssertEqual(t, "message", "user updated", r1["message"]) tt.AssertEqual(t, "message", "user updated", r1["message"])
tt.AssertEqual(t, "quota", 0, r1["quota"]) tt.AssertEqual(t, "quota", 0, r1["quota"])
tt.AssertEqual(t, "quota_max", 1000, r1["quota_max"]) tt.AssertEqual(t, "quota_max", 5000, r1["quota_max"])
tt.AssertEqual(t, "is_pro", true, r1["is_pro"]) tt.AssertEqual(t, "is_pro", true, r1["is_pro"])
} }

View File

@ -8,6 +8,7 @@ import (
"fmt" "fmt"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"net/url" "net/url"
"strings"
"testing" "testing"
"time" "time"
) )
@ -438,10 +439,13 @@ func TestSendLongContentPro(t *testing.T) {
uid := r0["user_id"].(string) uid := r0["user_id"].(string)
sendtok := r0["send_key"].(string) sendtok := r0["send_key"].(string)
str1k := strings.Repeat(".", 1000)
str100k := strings.Repeat(":", 100_000)
{ {
longContent := "" longContent := ""
for i := 0; i < 400; i++ { for i := 0; i < 400; i++ {
longContent += "123456789\n" // 10 * 400 = 4_000 (max = 16_384) longContent += "123456789\n" // 10 * 400 = 4_000 (max = 2_097_152)
} }
tt.RequestPost[tt.Void](t, baseUrl, "/", gin.H{ tt.RequestPost[tt.Void](t, baseUrl, "/", gin.H{
@ -455,7 +459,7 @@ func TestSendLongContentPro(t *testing.T) {
{ {
longContent := "" longContent := ""
for i := 0; i < 800; i++ { for i := 0; i < 800; i++ {
longContent += "123456789\n" // 10 * 800 = 8_000 (max = 16_384) longContent += "123456789\n" // 10 * 800 = 8_000 (max = 2_097_152)
} }
tt.RequestPost[tt.Void](t, baseUrl, "/", gin.H{ tt.RequestPost[tt.Void](t, baseUrl, "/", gin.H{
@ -469,8 +473,8 @@ func TestSendLongContentPro(t *testing.T) {
{ {
longContent := "" longContent := ""
for i := 0; i < 1600; i++ { for i := 0; i < 16; i++ {
longContent += "123456789\n" // 10 * 1600 = 16_000 (max = 16_384) longContent += str1k // 16 * 1000 = 16_000 (max = 2_097_152)
} }
tt.RequestPost[tt.Void](t, baseUrl, "/", gin.H{ tt.RequestPost[tt.Void](t, baseUrl, "/", gin.H{
@ -483,22 +487,8 @@ func TestSendLongContentPro(t *testing.T) {
{ {
longContent := "" longContent := ""
for i := 0; i < 1630; i++ { for i := 0; i < 21; i++ {
longContent += "123456789\n" // 10 * 1630 = 163_000 (max = 16_384) longContent += str100k // 21 * 200_000 = 2_100_000 (max = 2_097_152)
}
tt.RequestPost[tt.Void](t, baseUrl, "/", gin.H{
"key": sendtok,
"user_id": uid,
"title": "HelloWorld_042",
"content": longContent,
})
}
{
longContent := ""
for i := 0; i < 1640; i++ {
longContent += "123456789\n" // 10 * 1640 = 164_000 (max = 16_384)
} }
tt.RequestPostShouldFail(t, baseUrl, "/", gin.H{ tt.RequestPostShouldFail(t, baseUrl, "/", gin.H{
@ -1276,8 +1266,8 @@ func TestQuotaExceededPro(t *testing.T) {
sendtok := r0["send_key"].(string) sendtok := r0["send_key"].(string)
tt.AssertStrRepEqual(t, "quota.0", 0, r0["quota_used"]) tt.AssertStrRepEqual(t, "quota.0", 0, r0["quota_used"])
tt.AssertStrRepEqual(t, "quota.0", 1000, r0["quota_max"]) tt.AssertStrRepEqual(t, "quota.0", 5000, r0["quota_max"])
tt.AssertStrRepEqual(t, "quota.0", 1000, r0["quota_remaining"]) tt.AssertStrRepEqual(t, "quota.0", 5000, r0["quota_remaining"])
{ {
msg1 := tt.RequestPost[gin.H](t, baseUrl, "/", gin.H{ msg1 := tt.RequestPost[gin.H](t, baseUrl, "/", gin.H{
@ -1286,18 +1276,18 @@ func TestQuotaExceededPro(t *testing.T) {
"title": tt.ShortLipsum0(2), "title": tt.ShortLipsum0(2),
}) })
tt.AssertStrRepEqual(t, "quota.msg.1", 1, msg1["quota"]) tt.AssertStrRepEqual(t, "quota.msg.1", 1, msg1["quota"])
tt.AssertStrRepEqual(t, "quota.msg.1", 1000, msg1["quota_max"]) tt.AssertStrRepEqual(t, "quota.msg.1", 5000, msg1["quota_max"])
} }
{ {
usr := tt.RequestAuthGet[gin.H](t, admintok, baseUrl, fmt.Sprintf("/api/v2/users/%s", uid)) usr := tt.RequestAuthGet[gin.H](t, admintok, baseUrl, fmt.Sprintf("/api/v2/users/%s", uid))
tt.AssertStrRepEqual(t, "quota.1", 1, usr["quota_used"]) tt.AssertStrRepEqual(t, "quota.1", 1, usr["quota_used"])
tt.AssertStrRepEqual(t, "quota.1", 1000, usr["quota_max"]) tt.AssertStrRepEqual(t, "quota.1", 5000, usr["quota_max"])
tt.AssertStrRepEqual(t, "quota.1", 999, usr["quota_remaining"]) tt.AssertStrRepEqual(t, "quota.1", 4999, usr["quota_remaining"])
} }
for i := 0; i < 998; i++ { for i := 0; i < 4998; i++ {
tt.RequestPost[gin.H](t, baseUrl, "/", gin.H{ tt.RequestPost[gin.H](t, baseUrl, "/", gin.H{
"key": sendtok, "key": sendtok,
@ -1309,8 +1299,8 @@ func TestQuotaExceededPro(t *testing.T) {
{ {
usr := tt.RequestAuthGet[gin.H](t, admintok, baseUrl, fmt.Sprintf("/api/v2/users/%s", uid)) usr := tt.RequestAuthGet[gin.H](t, admintok, baseUrl, fmt.Sprintf("/api/v2/users/%s", uid))
tt.AssertStrRepEqual(t, "quota.999", 999, usr["quota_used"]) tt.AssertStrRepEqual(t, "quota.999", 4999, usr["quota_used"])
tt.AssertStrRepEqual(t, "quota.999", 1000, usr["quota_max"]) tt.AssertStrRepEqual(t, "quota.999", 5000, usr["quota_max"])
tt.AssertStrRepEqual(t, "quota.999", 1, usr["quota_remaining"]) tt.AssertStrRepEqual(t, "quota.999", 1, usr["quota_remaining"])
} }
@ -1319,15 +1309,15 @@ func TestQuotaExceededPro(t *testing.T) {
"user_id": uid, "user_id": uid,
"title": tt.ShortLipsum0(2), "title": tt.ShortLipsum0(2),
}) })
tt.AssertStrRepEqual(t, "quota.msg.1000", 1000, msg50["quota"]) tt.AssertStrRepEqual(t, "quota.msg.5000", 5000, msg50["quota"])
tt.AssertStrRepEqual(t, "quota.msg.1000", 1000, msg50["quota_max"]) tt.AssertStrRepEqual(t, "quota.msg.5000", 5000, msg50["quota_max"])
{ {
usr := tt.RequestAuthGet[gin.H](t, admintok, baseUrl, fmt.Sprintf("/api/v2/users/%s", uid)) usr := tt.RequestAuthGet[gin.H](t, admintok, baseUrl, fmt.Sprintf("/api/v2/users/%s", uid))
tt.AssertStrRepEqual(t, "quota.1000", 1000, usr["quota_used"]) tt.AssertStrRepEqual(t, "quota.5000", 5000, usr["quota_used"])
tt.AssertStrRepEqual(t, "quota.1000", 1000, usr["quota_max"]) tt.AssertStrRepEqual(t, "quota.5000", 5000, usr["quota_max"])
tt.AssertStrRepEqual(t, "quota.1000", 0, usr["quota_remaining"]) tt.AssertStrRepEqual(t, "quota.5000", 0, usr["quota_remaining"])
} }
tt.RequestPostShouldFail(t, baseUrl, "/", gin.H{ tt.RequestPostShouldFail(t, baseUrl, "/", gin.H{

View File

@ -150,7 +150,11 @@ func RequestAny[TResult any](t *testing.T, akey string, method string, baseURL s
TPrintln("") TPrintln("")
TPrintf("---------------- RESPONSE (%d) ----------------\n", resp.StatusCode) TPrintf("---------------- RESPONSE (%d) ----------------\n", resp.StatusCode)
if len(respBodyBin) > 100_000 {
TPrintln("[[RESPONSE TOO LONG]]")
} else {
TPrintln(langext.TryPrettyPrintJson(string(respBodyBin))) TPrintln(langext.TryPrettyPrintJson(string(respBodyBin)))
}
TryPrintTraceObj("---------------- -------- ----------------", respBodyBin, "") TryPrintTraceObj("---------------- -------- ----------------", respBodyBin, "")
TPrintln("---------------- -------- ----------------") TPrintln("---------------- -------- ----------------")
TPrintln("") TPrintln("")