Tests[**Subscription**]

This commit is contained in:
Mike Schwörer 2023-05-29 01:51:51 +02:00
parent 0daca2cf8f
commit 08587b7a7a
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
6 changed files with 1269 additions and 147 deletions

View File

@ -349,6 +349,22 @@ func (h APIHandler) CreateSubscription(g *gin.Context) ginresp.HTTPResponse {
return ginresp.APIError(g, 401, apierr.USER_AUTH_FAILED, "You are not authorized for this action", nil) return ginresp.APIError(g, 401, apierr.USER_AUTH_FAILED, "You are not authorized for this action", nil)
} }
existingSub, err := h.database.GetSubscriptionBySubscriber(ctx, u.UserID, channel.ChannelID)
if err != nil {
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to query existing subscription", err)
}
if existingSub != nil {
if !existingSub.Confirmed && channel.OwnerUserID == u.UserID {
err = h.database.UpdateSubscriptionConfirmed(ctx, existingSub.SubscriptionID, true)
if err != nil {
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to update subscription", err)
}
existingSub.Confirmed = true
}
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, existingSub.JSON()))
}
sub, err := h.database.CreateSubscription(ctx, u.UserID, channel, channel.OwnerUserID == u.UserID) sub, err := h.database.CreateSubscription(ctx, u.UserID, channel, channel.OwnerUserID == u.UserID)
if err != nil { if err != nil {
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to create subscription", err) return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to create subscription", err)

View File

@ -687,40 +687,40 @@ func TestListChannelSubscriptions(t *testing.T) {
} }
countBoth := func(oa1, oc1, ou1, ia1, ic1, iu1, oa2, oc2, ou2, ia2, ic2, iu2 int) { countBoth := func(oa1, oc1, ou1, ia1, ic1, iu1, oa2, oc2, ou2, ia2, ic2, iu2 int) {
sublist1oa := tt.RequestAuthGet[sublist](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions?selector=%s", data1.UserID, "outgoing_all")) sublist1oa := tt.RequestAuthGet[sublist](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions?selector=%s", data1.UID, "outgoing_all"))
tt.AssertEqual(t, "1:outgoing_all", oa1, len(sublist1oa.Subscriptions)) tt.AssertEqual(t, "1:outgoing_all", oa1, len(sublist1oa.Subscriptions))
sublist1oc := tt.RequestAuthGet[sublist](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions?selector=%s", data1.UserID, "outgoing_confirmed")) sublist1oc := tt.RequestAuthGet[sublist](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions?selector=%s", data1.UID, "outgoing_confirmed"))
tt.AssertEqual(t, "1:outgoing_confirmed", oc1, len(sublist1oc.Subscriptions)) tt.AssertEqual(t, "1:outgoing_confirmed", oc1, len(sublist1oc.Subscriptions))
sublist1ou := tt.RequestAuthGet[sublist](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions?selector=%s", data1.UserID, "outgoing_unconfirmed")) sublist1ou := tt.RequestAuthGet[sublist](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions?selector=%s", data1.UID, "outgoing_unconfirmed"))
tt.AssertEqual(t, "1:outgoing_unconfirmed", ou1, len(sublist1ou.Subscriptions)) tt.AssertEqual(t, "1:outgoing_unconfirmed", ou1, len(sublist1ou.Subscriptions))
sublist1ia := tt.RequestAuthGet[sublist](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions?selector=%s", data1.UserID, "incoming_all")) sublist1ia := tt.RequestAuthGet[sublist](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions?selector=%s", data1.UID, "incoming_all"))
tt.AssertEqual(t, "1:incoming_all", ia1, len(sublist1ia.Subscriptions)) tt.AssertEqual(t, "1:incoming_all", ia1, len(sublist1ia.Subscriptions))
sublist1ic := tt.RequestAuthGet[sublist](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions?selector=%s", data1.UserID, "incoming_confirmed")) sublist1ic := tt.RequestAuthGet[sublist](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions?selector=%s", data1.UID, "incoming_confirmed"))
tt.AssertEqual(t, "1:incoming_confirmed", ic1, len(sublist1ic.Subscriptions)) tt.AssertEqual(t, "1:incoming_confirmed", ic1, len(sublist1ic.Subscriptions))
sublist1iu := tt.RequestAuthGet[sublist](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions?selector=%s", data1.UserID, "incoming_unconfirmed")) sublist1iu := tt.RequestAuthGet[sublist](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions?selector=%s", data1.UID, "incoming_unconfirmed"))
tt.AssertEqual(t, "1:incoming_unconfirmed", iu1, len(sublist1iu.Subscriptions)) tt.AssertEqual(t, "1:incoming_unconfirmed", iu1, len(sublist1iu.Subscriptions))
sublist2oa := tt.RequestAuthGet[sublist](t, data2.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions?selector=%s", data2.UserID, "outgoing_all")) sublist2oa := tt.RequestAuthGet[sublist](t, data2.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions?selector=%s", data2.UID, "outgoing_all"))
tt.AssertEqual(t, "2:outgoing_all", oa2, len(sublist2oa.Subscriptions)) tt.AssertEqual(t, "2:outgoing_all", oa2, len(sublist2oa.Subscriptions))
sublist2oc := tt.RequestAuthGet[sublist](t, data2.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions?selector=%s", data2.UserID, "outgoing_confirmed")) sublist2oc := tt.RequestAuthGet[sublist](t, data2.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions?selector=%s", data2.UID, "outgoing_confirmed"))
tt.AssertEqual(t, "2:outgoing_confirmed", oc2, len(sublist2oc.Subscriptions)) tt.AssertEqual(t, "2:outgoing_confirmed", oc2, len(sublist2oc.Subscriptions))
sublist2ou := tt.RequestAuthGet[sublist](t, data2.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions?selector=%s", data2.UserID, "outgoing_unconfirmed")) sublist2ou := tt.RequestAuthGet[sublist](t, data2.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions?selector=%s", data2.UID, "outgoing_unconfirmed"))
tt.AssertEqual(t, "2:outgoing_unconfirmed", ou2, len(sublist2ou.Subscriptions)) tt.AssertEqual(t, "2:outgoing_unconfirmed", ou2, len(sublist2ou.Subscriptions))
sublist2ia := tt.RequestAuthGet[sublist](t, data2.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions?selector=%s", data2.UserID, "incoming_all")) sublist2ia := tt.RequestAuthGet[sublist](t, data2.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions?selector=%s", data2.UID, "incoming_all"))
tt.AssertEqual(t, "2:incoming_all", ia2, len(sublist2ia.Subscriptions)) tt.AssertEqual(t, "2:incoming_all", ia2, len(sublist2ia.Subscriptions))
sublist2ic := tt.RequestAuthGet[sublist](t, data2.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions?selector=%s", data2.UserID, "incoming_confirmed")) sublist2ic := tt.RequestAuthGet[sublist](t, data2.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions?selector=%s", data2.UID, "incoming_confirmed"))
tt.AssertEqual(t, "2:incoming_confirmed", ic2, len(sublist2ic.Subscriptions)) tt.AssertEqual(t, "2:incoming_confirmed", ic2, len(sublist2ic.Subscriptions))
sublist2iu := tt.RequestAuthGet[sublist](t, data2.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions?selector=%s", data2.UserID, "incoming_unconfirmed")) sublist2iu := tt.RequestAuthGet[sublist](t, data2.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions?selector=%s", data2.UID, "incoming_unconfirmed"))
tt.AssertEqual(t, "2:incoming_unconfirmed", iu2, len(sublist2iu.Subscriptions)) tt.AssertEqual(t, "2:incoming_unconfirmed", iu2, len(sublist2iu.Subscriptions))
} }
@ -730,13 +730,13 @@ func TestListChannelSubscriptions(t *testing.T) {
0, 0, 0, 0, 0, 0,
0, 0, 0) 0, 0, 0)
chan1 := tt.RequestAuthPost[chanobj](t, data2.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels", data2.UserID), gin.H{ chan1 := tt.RequestAuthPost[chanobj](t, data2.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels", data2.UID), gin.H{
"name": "Chan1", "name": "Chan1",
}) })
chan2 := tt.RequestAuthPost[chanobj](t, data2.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels", data2.UserID), gin.H{ chan2 := tt.RequestAuthPost[chanobj](t, data2.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels", data2.UID), gin.H{
"name": "Chan2", "name": "Chan2",
}) })
chan3 := tt.RequestAuthPost[chanobj](t, data2.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels", data2.UserID), gin.H{ chan3 := tt.RequestAuthPost[chanobj](t, data2.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels", data2.UID), gin.H{
"name": "Chan3", "name": "Chan3",
}) })
@ -746,15 +746,15 @@ func TestListChannelSubscriptions(t *testing.T) {
3, 3, 0, 3, 3, 0,
3, 3, 0) 3, 3, 0)
sub1 := tt.RequestAuthPost[gin.H](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions?chan_subscribe_key=%s", data1.UserID, chan1.SubscribeKey), gin.H{ sub1 := tt.RequestAuthPost[gin.H](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions?chan_subscribe_key=%s", data1.UID, chan1.SubscribeKey), gin.H{
"channel_owner_user_id": data2.UserID, "channel_owner_user_id": data2.UID,
"channel_internal_name": "Chan1", "channel_internal_name": "Chan1",
}) })
sub2 := tt.RequestAuthPost[gin.H](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions?chan_subscribe_key=%s", data1.UserID, chan2.SubscribeKey), gin.H{ sub2 := tt.RequestAuthPost[gin.H](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions?chan_subscribe_key=%s", data1.UID, chan2.SubscribeKey), gin.H{
"channel_id": chan2.ChannelId, "channel_id": chan2.ChannelId,
}) })
sub3 := tt.RequestAuthPost[gin.H](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions?chan_subscribe_key=%s", data1.UserID, chan3.SubscribeKey), gin.H{ sub3 := tt.RequestAuthPost[gin.H](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions?chan_subscribe_key=%s", data1.UID, chan3.SubscribeKey), gin.H{
"channel_owner_user_id": data2.UserID, "channel_owner_user_id": data2.UID,
"channel_internal_name": "Chan3", "channel_internal_name": "Chan3",
}) })
@ -764,7 +764,7 @@ func TestListChannelSubscriptions(t *testing.T) {
3, 3, 0, 3, 3, 0,
6, 3, 3) 6, 3, 3)
tt.RequestAuthPatch[gin.H](t, data2.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions/%s", data2.UserID, sub1["subscription_id"]), gin.H{ tt.RequestAuthPatch[gin.H](t, data2.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions/%s", data2.UID, sub1["subscription_id"]), gin.H{
"confirmed": true, "confirmed": true,
}) })
@ -774,7 +774,7 @@ func TestListChannelSubscriptions(t *testing.T) {
3, 3, 0, 3, 3, 0,
6, 4, 2) 6, 4, 2)
tt.RequestAuthPatch[gin.H](t, data2.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions/%s", data2.UserID, sub2["subscription_id"]), gin.H{ tt.RequestAuthPatch[gin.H](t, data2.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions/%s", data2.UID, sub2["subscription_id"]), gin.H{
"confirmed": true, "confirmed": true,
}) })
@ -784,7 +784,7 @@ func TestListChannelSubscriptions(t *testing.T) {
3, 3, 0, 3, 3, 0,
6, 5, 1) 6, 5, 1)
tt.RequestAuthPatch[gin.H](t, data2.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions/%s", data2.UserID, sub3["subscription_id"]), gin.H{ tt.RequestAuthPatch[gin.H](t, data2.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions/%s", data2.UID, sub3["subscription_id"]), gin.H{
"confirmed": true, "confirmed": true,
}) })
@ -794,7 +794,7 @@ func TestListChannelSubscriptions(t *testing.T) {
3, 3, 0, 3, 3, 0,
6, 6, 0) 6, 6, 0)
tt.RequestAuthDelete[gin.H](t, data2.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions/%s", data2.UserID, sub1["subscription_id"]), gin.H{}) tt.RequestAuthDelete[gin.H](t, data2.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions/%s", data2.UID, sub1["subscription_id"]), gin.H{})
countBoth( countBoth(
2, 2, 0, 2, 2, 0,
@ -802,7 +802,7 @@ func TestListChannelSubscriptions(t *testing.T) {
3, 3, 0, 3, 3, 0,
5, 5, 0) 5, 5, 0)
tt.RequestAuthDelete[gin.H](t, data2.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions/%s", data2.UserID, sub2["subscription_id"]), gin.H{}) tt.RequestAuthDelete[gin.H](t, data2.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions/%s", data2.UID, sub2["subscription_id"]), gin.H{})
countBoth( countBoth(
1, 1, 0, 1, 1, 0,
@ -810,7 +810,7 @@ func TestListChannelSubscriptions(t *testing.T) {
3, 3, 0, 3, 3, 0,
4, 4, 0) 4, 4, 0)
tt.RequestAuthDelete[gin.H](t, data2.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions/%s", data2.UserID, sub3["subscription_id"]), gin.H{}) tt.RequestAuthDelete[gin.H](t, data2.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions/%s", data2.UID, sub3["subscription_id"]), gin.H{})
countBoth( countBoth(
0, 0, 0, 0, 0, 0,
@ -818,9 +818,9 @@ func TestListChannelSubscriptions(t *testing.T) {
3, 3, 0, 3, 3, 0,
3, 3, 0) 3, 3, 0)
sublistRem := tt.RequestAuthGet[sublist](t, data2.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions?selector=%s", data2.UserID, "incoming_confirmed")) sublistRem := tt.RequestAuthGet[sublist](t, data2.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions?selector=%s", data2.UID, "incoming_confirmed"))
for _, v := range sublistRem.Subscriptions { for _, v := range sublistRem.Subscriptions {
tt.RequestAuthDelete[gin.H](t, data2.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions/%s", data2.UserID, v.SubscriptionId), gin.H{}) tt.RequestAuthDelete[gin.H](t, data2.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions/%s", data2.UID, v.SubscriptionId), gin.H{})
} }
countBoth( countBoth(
@ -883,11 +883,11 @@ func TestListChannelMessagesOfUnsubscribed(t *testing.T) {
Channels []chanobj `json:"channels"` Channels []chanobj `json:"channels"`
} }
chan1 := tt.RequestAuthPost[chanobj](t, data2.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels", data2.UserID), gin.H{ chan1 := tt.RequestAuthPost[chanobj](t, data2.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels", data2.UID), gin.H{
"name": "Chan1", "name": "Chan1",
}) })
tt.RequestAuthGetShouldFail(t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels/%s/messages", data1.UserID, chan1.ChannelId), 401, apierr.USER_AUTH_FAILED) tt.RequestAuthGetShouldFail(t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels/%s/messages", data1.UID, chan1.ChannelId), 401, apierr.USER_AUTH_FAILED)
} }
func TestListChannelMessagesOfUnconfirmed1(t *testing.T) { func TestListChannelMessagesOfUnconfirmed1(t *testing.T) {
@ -943,16 +943,16 @@ func TestListChannelMessagesOfUnconfirmed1(t *testing.T) {
Channels []chanobj `json:"channels"` Channels []chanobj `json:"channels"`
} }
chan1 := tt.RequestAuthPost[chanobj](t, data2.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels", data2.UserID), gin.H{ chan1 := tt.RequestAuthPost[chanobj](t, data2.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels", data2.UID), gin.H{
"name": "Chan1", "name": "Chan1",
}) })
tt.RequestAuthPost[gin.H](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions?chan_subscribe_key=%s", data1.UserID, chan1.SubscribeKey), gin.H{ tt.RequestAuthPost[gin.H](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions?chan_subscribe_key=%s", data1.UID, chan1.SubscribeKey), gin.H{
"channel_owner_user_id": data2.UserID, "channel_owner_user_id": data2.UID,
"channel_internal_name": "Chan1", "channel_internal_name": "Chan1",
}) })
tt.RequestAuthGetShouldFail(t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels/%s/messages", data1.UserID, chan1.ChannelId), 401, apierr.USER_AUTH_FAILED) tt.RequestAuthGetShouldFail(t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels/%s/messages", data1.UID, chan1.ChannelId), 401, apierr.USER_AUTH_FAILED)
} }
func TestListChannelMessagesOfUnconfirmed2(t *testing.T) { func TestListChannelMessagesOfUnconfirmed2(t *testing.T) {
@ -1008,15 +1008,15 @@ func TestListChannelMessagesOfUnconfirmed2(t *testing.T) {
Channels []chanobj `json:"channels"` Channels []chanobj `json:"channels"`
} }
chan1 := tt.RequestAuthPost[chanobj](t, data2.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels", data2.UserID), gin.H{ chan1 := tt.RequestAuthPost[chanobj](t, data2.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels", data2.UID), gin.H{
"name": "Chan1", "name": "Chan1",
}) })
tt.RequestAuthPost[gin.H](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions?chan_subscribe_key=%s", data1.UserID, chan1.SubscribeKey), gin.H{ tt.RequestAuthPost[gin.H](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions?chan_subscribe_key=%s", data1.UID, chan1.SubscribeKey), gin.H{
"channel_id": chan1.ChannelId, "channel_id": chan1.ChannelId,
}) })
tt.RequestAuthGetShouldFail(t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels/%s/messages", data1.UserID, chan1.ChannelId), 401, apierr.USER_AUTH_FAILED) tt.RequestAuthGetShouldFail(t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels/%s/messages", data1.UID, chan1.ChannelId), 401, apierr.USER_AUTH_FAILED)
} }
func TestListChannelMessagesOfRevokedConfirmation(t *testing.T) { func TestListChannelMessagesOfRevokedConfirmation(t *testing.T) {
@ -1072,21 +1072,21 @@ func TestListChannelMessagesOfRevokedConfirmation(t *testing.T) {
Channels []chanobj `json:"channels"` Channels []chanobj `json:"channels"`
} }
chan1 := tt.RequestAuthPost[chanobj](t, data2.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels", data2.UserID), gin.H{ chan1 := tt.RequestAuthPost[chanobj](t, data2.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels", data2.UID), gin.H{
"name": "Chan1", "name": "Chan1",
}) })
sub1 := tt.RequestAuthPost[gin.H](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions?chan_subscribe_key=%s", data1.UserID, chan1.SubscribeKey), gin.H{ sub1 := tt.RequestAuthPost[gin.H](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions?chan_subscribe_key=%s", data1.UID, chan1.SubscribeKey), gin.H{
"channel_id": chan1.ChannelId, "channel_id": chan1.ChannelId,
}) })
tt.RequestAuthPatch[gin.H](t, data2.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions/%s", data2.UserID, sub1["subscription_id"]), gin.H{ tt.RequestAuthPatch[gin.H](t, data2.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions/%s", data2.UID, sub1["subscription_id"]), gin.H{
"confirmed": true, "confirmed": true,
}) })
tt.RequestAuthGet[tt.Void](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels/%s/messages", data1.UserID, chan1.ChannelId)) tt.RequestAuthGet[tt.Void](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels/%s/messages", data1.UID, chan1.ChannelId))
tt.RequestAuthDelete[gin.H](t, data2.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions/%s", data2.UserID, sub1["subscription_id"]), gin.H{}) tt.RequestAuthDelete[gin.H](t, data2.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/subscriptions/%s", data2.UID, sub1["subscription_id"]), gin.H{})
tt.RequestAuthGetShouldFail(t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels/%s/messages", data1.UserID, chan1.ChannelId), 401, apierr.USER_AUTH_FAILED) tt.RequestAuthGetShouldFail(t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels/%s/messages", data1.UID, chan1.ChannelId), 401, apierr.USER_AUTH_FAILED)
} }

View File

@ -29,7 +29,7 @@ func TestTokenKeys(t *testing.T) {
} }
{ {
klist := tt.RequestAuthGet[keylist](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys", data.UserID)) klist := tt.RequestAuthGet[keylist](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys", data.UID))
tt.AssertEqual(t, "len(keys)", 3, len(klist.Keys)) tt.AssertEqual(t, "len(keys)", 3, len(klist.Keys))
tt.AssertArrAny(t, "keys->any[Admin]", klist.Keys, func(s keyobj) bool { tt.AssertArrAny(t, "keys->any[Admin]", klist.Keys, func(s keyobj) bool {
@ -43,7 +43,7 @@ func TestTokenKeys(t *testing.T) {
}) })
} }
key2 := tt.RequestAuthPost[keyobj](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys", data.UserID), gin.H{ key2 := tt.RequestAuthPost[keyobj](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys", data.UID), gin.H{
"all_channels": true, "all_channels": true,
"channels": []string{}, "channels": []string{},
"name": "Admin2", "name": "Admin2",
@ -55,33 +55,33 @@ func TestTokenKeys(t *testing.T) {
tt.AssertEqual(t, "AllChannels", true, key2.AllChannels) tt.AssertEqual(t, "AllChannels", true, key2.AllChannels)
{ {
klist := tt.RequestAuthGet[keylist](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys", data.UserID)) klist := tt.RequestAuthGet[keylist](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys", data.UID))
tt.AssertEqual(t, "len(keys)", 4, len(klist.Keys)) tt.AssertEqual(t, "len(keys)", 4, len(klist.Keys))
} }
key3 := tt.RequestAuthGet[keyobj](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys/%s", data.UserID, key2.KeytokenId)) key3 := tt.RequestAuthGet[keyobj](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys/%s", data.UID, key2.KeytokenId))
tt.AssertEqual(t, "KeytokenId", key2.KeytokenId, key3.KeytokenId) tt.AssertEqual(t, "KeytokenId", key2.KeytokenId, key3.KeytokenId)
tt.AssertEqual(t, "UserID", data.UserID, key3.OwnerUserId) tt.AssertEqual(t, "UserID", data.UID, key3.OwnerUserId)
tt.AssertEqual(t, "Name", "Admin2", key3.Name) tt.AssertEqual(t, "Name", "Admin2", key3.Name)
tt.AssertEqual(t, "Permissions", "A", key3.Permissions) tt.AssertEqual(t, "Permissions", "A", key3.Permissions)
tt.AssertEqual(t, "AllChannels", true, key3.AllChannels) tt.AssertEqual(t, "AllChannels", true, key3.AllChannels)
tt.RequestAuthDelete[tt.Void](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys/%s", data.UserID, key2.KeytokenId), gin.H{}) tt.RequestAuthDelete[tt.Void](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys/%s", data.UID, key2.KeytokenId), gin.H{})
tt.RequestAuthGetShouldFail(t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys/%s", data.UserID, key2.KeytokenId), 404, apierr.KEY_NOT_FOUND) tt.RequestAuthGetShouldFail(t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys/%s", data.UID, key2.KeytokenId), 404, apierr.KEY_NOT_FOUND)
{ {
klist := tt.RequestAuthGet[keylist](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys", data.UserID)) klist := tt.RequestAuthGet[keylist](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys", data.UID))
tt.AssertEqual(t, "len(keys)", 3, len(klist.Keys)) tt.AssertEqual(t, "len(keys)", 3, len(klist.Keys))
} }
chan0 := tt.RequestAuthPost[gin.H](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels", data.UserID), gin.H{ chan0 := tt.RequestAuthPost[gin.H](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels", data.UID), gin.H{
"name": "testchan1", "name": "testchan1",
}) })
chanid := fmt.Sprintf("%v", chan0["channel_id"]) chanid := fmt.Sprintf("%v", chan0["channel_id"])
key4 := tt.RequestAuthPost[keyobj](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys", data.UserID), gin.H{ key4 := tt.RequestAuthPost[keyobj](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys", data.UID), gin.H{
"all_channels": false, "all_channels": false,
"channels": []string{chanid}, "channels": []string{chanid},
"name": "TKey1", "name": "TKey1",
@ -92,7 +92,7 @@ func TestTokenKeys(t *testing.T) {
tt.AssertEqual(t, "AllChannels", false, key4.AllChannels) tt.AssertEqual(t, "AllChannels", false, key4.AllChannels)
tt.AssertStrRepEqual(t, "Channels", []string{chanid}, key4.Channels) tt.AssertStrRepEqual(t, "Channels", []string{chanid}, key4.Channels)
key5 := tt.RequestAuthPatch[keyobj](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys/%s", data.UserID, key4.KeytokenId), gin.H{ key5 := tt.RequestAuthPatch[keyobj](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys/%s", data.UID, key4.KeytokenId), gin.H{
"all_channels": true, "all_channels": true,
"channels": []string{}, "channels": []string{},
"name": "TKey2-A", "name": "TKey2-A",
@ -103,13 +103,13 @@ func TestTokenKeys(t *testing.T) {
tt.AssertEqual(t, "AllChannels", true, key5.AllChannels) tt.AssertEqual(t, "AllChannels", true, key5.AllChannels)
tt.AssertStrRepEqual(t, "Channels", []string{}, key5.Channels) tt.AssertStrRepEqual(t, "Channels", []string{}, key5.Channels)
key6 := tt.RequestAuthGet[keyobj](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys/%s", data.UserID, key5.KeytokenId)) key6 := tt.RequestAuthGet[keyobj](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys/%s", data.UID, key5.KeytokenId))
tt.AssertEqual(t, "Name", "TKey2-A", key6.Name) tt.AssertEqual(t, "Name", "TKey2-A", key6.Name)
tt.AssertEqual(t, "Permissions", "A", key6.Permissions) tt.AssertEqual(t, "Permissions", "A", key6.Permissions)
tt.AssertEqual(t, "AllChannels", true, key6.AllChannels) tt.AssertEqual(t, "AllChannels", true, key6.AllChannels)
tt.AssertStrRepEqual(t, "Channels", []string{}, key6.Channels) tt.AssertStrRepEqual(t, "Channels", []string{}, key6.Channels)
key7 := tt.RequestAuthPost[keyobj](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys", data.UserID), gin.H{ key7 := tt.RequestAuthPost[keyobj](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys", data.UID), gin.H{
"all_channels": false, "all_channels": false,
"channels": []string{chanid}, "channels": []string{chanid},
"name": "TKey7", "name": "TKey7",
@ -117,13 +117,13 @@ func TestTokenKeys(t *testing.T) {
}) })
{ {
klist := tt.RequestAuthGet[keylist](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys", data.UserID)) klist := tt.RequestAuthGet[keylist](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys", data.UID))
tt.AssertEqual(t, "len(keys)", 5, len(klist.Keys)) tt.AssertEqual(t, "len(keys)", 5, len(klist.Keys))
} }
msg1s := tt.RequestPost[gin.H](t, baseUrl, "/", gin.H{ msg1s := tt.RequestPost[gin.H](t, baseUrl, "/", gin.H{
"key": key7.Token, "key": key7.Token,
"user_id": data.UserID, "user_id": data.UID,
"channel": "testchan1", "channel": "testchan1",
"title": "HelloWorld_001", "title": "HelloWorld_001",
}) })
@ -134,22 +134,22 @@ func TestTokenKeys(t *testing.T) {
tt.RequestPostShouldFail(t, baseUrl, "/", gin.H{ tt.RequestPostShouldFail(t, baseUrl, "/", gin.H{
"key": key7.Token, "key": key7.Token,
"user_id": data.UserID, "user_id": data.UID,
"channel": "testchan2", "channel": "testchan2",
"title": "HelloWorld_001", "title": "HelloWorld_001",
}, 401, apierr.USER_AUTH_FAILED) // wrong channel }, 401, apierr.USER_AUTH_FAILED) // wrong channel
tt.RequestPostShouldFail(t, baseUrl, "/", gin.H{ tt.RequestPostShouldFail(t, baseUrl, "/", gin.H{
"key": key7.Token, "key": key7.Token,
"user_id": data.UserID, "user_id": data.UID,
"title": "HelloWorld_001", "title": "HelloWorld_001",
}, 401, apierr.USER_AUTH_FAILED) // no channel (=main) }, 401, apierr.USER_AUTH_FAILED) // no channel (=main)
tt.RequestAuthGetShouldFail(t, key7.Token, baseUrl, fmt.Sprintf("/api/v2/users/%s", data.UserID), 401, apierr.USER_AUTH_FAILED) // no user read perm tt.RequestAuthGetShouldFail(t, key7.Token, baseUrl, fmt.Sprintf("/api/v2/users/%s", data.UID), 401, apierr.USER_AUTH_FAILED) // no user read perm
tt.RequestAuthPatchShouldFail(t, key7.Token, baseUrl, "/api/v2/users/"+data.UserID, gin.H{"username": "my_user_001"}, 401, apierr.USER_AUTH_FAILED) // no user update perm tt.RequestAuthPatchShouldFail(t, key7.Token, baseUrl, "/api/v2/users/"+data.UID, gin.H{"username": "my_user_001"}, 401, apierr.USER_AUTH_FAILED) // no user update perm
key8 := tt.RequestAuthPost[keyobj](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys", data.UserID), gin.H{ key8 := tt.RequestAuthPost[keyobj](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys", data.UID), gin.H{
"all_channels": true, "all_channels": true,
"channels": []string{}, "channels": []string{},
"name": "TKey7", "name": "TKey7",
@ -158,7 +158,7 @@ func TestTokenKeys(t *testing.T) {
tt.RequestPostShouldFail(t, baseUrl, "/", gin.H{ tt.RequestPostShouldFail(t, baseUrl, "/", gin.H{
"key": key8.Token, "key": key8.Token,
"user_id": data.UserID, "user_id": data.UID,
"title": "HelloWorld_001", "title": "HelloWorld_001",
}, 401, apierr.USER_AUTH_FAILED) // no send perm }, 401, apierr.USER_AUTH_FAILED) // no send perm
@ -184,7 +184,7 @@ func TestTokenKeysInitial(t *testing.T) {
Keys []keyobj `json:"keys"` Keys []keyobj `json:"keys"`
} }
klist := tt.RequestAuthGet[keylist](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys", data.UserID)) klist := tt.RequestAuthGet[keylist](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys", data.UID))
tt.AssertEqual(t, "len(keys)", 3, len(klist.Keys)) tt.AssertEqual(t, "len(keys)", 3, len(klist.Keys))
tt.AssertArrAny(t, "keys->any[Admin]", klist.Keys, func(s keyobj) bool { tt.AssertArrAny(t, "keys->any[Admin]", klist.Keys, func(s keyobj) bool {
@ -218,7 +218,7 @@ func TestTokenKeysCreate(t *testing.T) {
Keys []keyobj `json:"keys"` Keys []keyobj `json:"keys"`
} }
key2 := tt.RequestAuthPost[keyobj](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys", data.UserID), gin.H{ key2 := tt.RequestAuthPost[keyobj](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys", data.UID), gin.H{
"all_channels": true, "all_channels": true,
"channels": []string{}, "channels": []string{},
"name": "Admin2", "name": "Admin2",
@ -230,14 +230,14 @@ func TestTokenKeysCreate(t *testing.T) {
tt.AssertEqual(t, "AllChannels", true, key2.AllChannels) tt.AssertEqual(t, "AllChannels", true, key2.AllChannels)
{ {
klist := tt.RequestAuthGet[keylist](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys", data.UserID)) klist := tt.RequestAuthGet[keylist](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys", data.UID))
tt.AssertEqual(t, "len(keys)", 4, len(klist.Keys)) tt.AssertEqual(t, "len(keys)", 4, len(klist.Keys))
} }
key3 := tt.RequestAuthGet[keyobj](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys/%s", data.UserID, key2.KeytokenId)) key3 := tt.RequestAuthGet[keyobj](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys/%s", data.UID, key2.KeytokenId))
tt.AssertEqual(t, "KeytokenId", key2.KeytokenId, key3.KeytokenId) tt.AssertEqual(t, "KeytokenId", key2.KeytokenId, key3.KeytokenId)
tt.AssertEqual(t, "UserID", data.UserID, key3.OwnerUserId) tt.AssertEqual(t, "UserID", data.UID, key3.OwnerUserId)
tt.AssertEqual(t, "Name", "Admin2", key3.Name) tt.AssertEqual(t, "Name", "Admin2", key3.Name)
tt.AssertEqual(t, "Permissions", "A", key3.Permissions) tt.AssertEqual(t, "Permissions", "A", key3.Permissions)
tt.AssertEqual(t, "AllChannels", true, key3.AllChannels) tt.AssertEqual(t, "AllChannels", true, key3.AllChannels)
@ -264,7 +264,7 @@ func TestTokenKeysUpdate(t *testing.T) {
Keys []keyobj `json:"keys"` Keys []keyobj `json:"keys"`
} }
key2 := tt.RequestAuthPost[keyobj](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys", data.UserID), gin.H{ key2 := tt.RequestAuthPost[keyobj](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys", data.UID), gin.H{
"all_channels": true, "all_channels": true,
"channels": []string{}, "channels": []string{},
"name": "Admin2", "name": "Admin2",
@ -275,15 +275,15 @@ func TestTokenKeysUpdate(t *testing.T) {
tt.AssertEqual(t, "Permissions", "A", key2.Permissions) tt.AssertEqual(t, "Permissions", "A", key2.Permissions)
tt.AssertEqual(t, "AllChannels", true, key2.AllChannels) tt.AssertEqual(t, "AllChannels", true, key2.AllChannels)
key3 := tt.RequestAuthGet[keyobj](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys/%s", data.UserID, key2.KeytokenId)) key3 := tt.RequestAuthGet[keyobj](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys/%s", data.UID, key2.KeytokenId))
tt.AssertEqual(t, "KeytokenId", key2.KeytokenId, key3.KeytokenId) tt.AssertEqual(t, "KeytokenId", key2.KeytokenId, key3.KeytokenId)
tt.AssertEqual(t, "UserID", data.UserID, key3.OwnerUserId) tt.AssertEqual(t, "UserID", data.UID, key3.OwnerUserId)
tt.AssertEqual(t, "Name", "Admin2", key3.Name) tt.AssertEqual(t, "Name", "Admin2", key3.Name)
tt.AssertEqual(t, "Permissions", "A", key3.Permissions) tt.AssertEqual(t, "Permissions", "A", key3.Permissions)
tt.AssertEqual(t, "AllChannels", true, key3.AllChannels) tt.AssertEqual(t, "AllChannels", true, key3.AllChannels)
key5 := tt.RequestAuthPatch[keyobj](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys/%s", data.UserID, key3.KeytokenId), gin.H{ key5 := tt.RequestAuthPatch[keyobj](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys/%s", data.UID, key3.KeytokenId), gin.H{
"name": "Hello", "name": "Hello",
}) })
tt.AssertEqual(t, "Name", "Hello", key5.Name) tt.AssertEqual(t, "Name", "Hello", key5.Name)
@ -291,7 +291,7 @@ func TestTokenKeysUpdate(t *testing.T) {
tt.AssertEqual(t, "AllChannels", true, key5.AllChannels) tt.AssertEqual(t, "AllChannels", true, key5.AllChannels)
tt.AssertStrRepEqual(t, "Channels", []string{}, key5.Channels) tt.AssertStrRepEqual(t, "Channels", []string{}, key5.Channels)
key6 := tt.RequestAuthGet[keyobj](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys/%s", data.UserID, key5.KeytokenId)) key6 := tt.RequestAuthGet[keyobj](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys/%s", data.UID, key5.KeytokenId))
tt.AssertEqual(t, "Name", "Hello", key6.Name) tt.AssertEqual(t, "Name", "Hello", key6.Name)
tt.AssertEqual(t, "Permissions", "A", key6.Permissions) tt.AssertEqual(t, "Permissions", "A", key6.Permissions)
tt.AssertEqual(t, "AllChannels", true, key6.AllChannels) tt.AssertEqual(t, "AllChannels", true, key6.AllChannels)
@ -319,7 +319,7 @@ func TestTokenKeysDelete(t *testing.T) {
Keys []keyobj `json:"keys"` Keys []keyobj `json:"keys"`
} }
key2 := tt.RequestAuthPost[keyobj](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys", data.UserID), gin.H{ key2 := tt.RequestAuthPost[keyobj](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys", data.UID), gin.H{
"all_channels": true, "all_channels": true,
"channels": []string{}, "channels": []string{},
"name": "Admin2", "name": "Admin2",
@ -331,14 +331,14 @@ func TestTokenKeysDelete(t *testing.T) {
tt.AssertEqual(t, "AllChannels", true, key2.AllChannels) tt.AssertEqual(t, "AllChannels", true, key2.AllChannels)
{ {
klist := tt.RequestAuthGet[keylist](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys", data.UserID)) klist := tt.RequestAuthGet[keylist](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys", data.UID))
tt.AssertEqual(t, "len(keys)", 4, len(klist.Keys)) tt.AssertEqual(t, "len(keys)", 4, len(klist.Keys))
} }
tt.RequestAuthDelete[tt.Void](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys/%s", data.UserID, key2.KeytokenId), gin.H{}) tt.RequestAuthDelete[tt.Void](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys/%s", data.UID, key2.KeytokenId), gin.H{})
{ {
klist := tt.RequestAuthGet[keylist](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys", data.UserID)) klist := tt.RequestAuthGet[keylist](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys", data.UID))
tt.AssertEqual(t, "len(keys)", 3, len(klist.Keys)) tt.AssertEqual(t, "len(keys)", 3, len(klist.Keys))
} }
@ -364,7 +364,7 @@ func TestTokenKeysDeleteSelf(t *testing.T) {
Keys []keyobj `json:"keys"` Keys []keyobj `json:"keys"`
} }
klist := tt.RequestAuthGet[keylist](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys", data.UserID)) klist := tt.RequestAuthGet[keylist](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys", data.UID))
ak := "" ak := ""
for _, v := range klist.Keys { for _, v := range klist.Keys {
@ -373,7 +373,7 @@ func TestTokenKeysDeleteSelf(t *testing.T) {
} }
} }
tt.RequestAuthDeleteShouldFail(t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys/%s", data.UserID, ak), gin.H{}, 400, apierr.CANNOT_SELFDELETE_KEY) tt.RequestAuthDeleteShouldFail(t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys/%s", data.UID, ak), gin.H{}, 400, apierr.CANNOT_SELFDELETE_KEY)
} }
func TestTokenKeysDowngradeSelf(t *testing.T) { func TestTokenKeysDowngradeSelf(t *testing.T) {
@ -396,7 +396,7 @@ func TestTokenKeysDowngradeSelf(t *testing.T) {
Keys []keyobj `json:"keys"` Keys []keyobj `json:"keys"`
} }
klist := tt.RequestAuthGet[keylist](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys", data.UserID)) klist := tt.RequestAuthGet[keylist](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys", data.UID))
ak := "" ak := ""
for _, v := range klist.Keys { for _, v := range klist.Keys {
@ -405,25 +405,25 @@ func TestTokenKeysDowngradeSelf(t *testing.T) {
} }
} }
tt.RequestAuthPatchShouldFail(t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys/%s", data.UserID, ak), gin.H{ tt.RequestAuthPatchShouldFail(t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys/%s", data.UID, ak), gin.H{
"permissions": "CR", "permissions": "CR",
}, 400, apierr.CANNOT_SELFUPDATE_KEY) }, 400, apierr.CANNOT_SELFUPDATE_KEY)
tt.RequestAuthPatchShouldFail(t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys/%s", data.UserID, ak), gin.H{ tt.RequestAuthPatchShouldFail(t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys/%s", data.UID, ak), gin.H{
"all_channels": false, "all_channels": false,
}, 400, apierr.CANNOT_SELFUPDATE_KEY) }, 400, apierr.CANNOT_SELFUPDATE_KEY)
tt.RequestAuthPatchShouldFail(t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys/%s", data.UserID, ak), gin.H{ tt.RequestAuthPatchShouldFail(t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys/%s", data.UID, ak), gin.H{
"channels": []string{"main"}, "channels": []string{"main"},
}, 400, apierr.CANNOT_SELFUPDATE_KEY) }, 400, apierr.CANNOT_SELFUPDATE_KEY)
tt.RequestAuthPatch[tt.Void](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys/%s", data.UserID, ak), gin.H{ tt.RequestAuthPatch[tt.Void](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys/%s", data.UID, ak), gin.H{
"name": "This-is-allowed", "name": "This-is-allowed",
}) })
keyOut := tt.RequestAuthGet[keyobj](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys/%s", data.UserID, ak)) keyOut := tt.RequestAuthGet[keyobj](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys/%s", data.UID, ak))
tt.AssertEqual(t, "UserID", data.UserID, keyOut.OwnerUserId) tt.AssertEqual(t, "UserID", data.UID, keyOut.OwnerUserId)
tt.AssertEqual(t, "Name", "This-is-allowed", keyOut.Name) tt.AssertEqual(t, "Name", "This-is-allowed", keyOut.Name)
tt.AssertEqual(t, "Permissions", "A", keyOut.Permissions) tt.AssertEqual(t, "Permissions", "A", keyOut.Permissions)
tt.AssertEqual(t, "AllChannels", true, keyOut.AllChannels) tt.AssertEqual(t, "AllChannels", true, keyOut.AllChannels)
@ -448,12 +448,12 @@ func TestTokenKeysPermissions(t *testing.T) {
Token string `json:"token"` // only in create Token string `json:"token"` // only in create
} }
chan0 := tt.RequestAuthPost[gin.H](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels", data.UserID), gin.H{ chan0 := tt.RequestAuthPost[gin.H](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels", data.UID), gin.H{
"name": "testchan1", "name": "testchan1",
}) })
chanid := fmt.Sprintf("%v", chan0["channel_id"]) chanid := fmt.Sprintf("%v", chan0["channel_id"])
key7 := tt.RequestAuthPost[keyobj](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys", data.UserID), gin.H{ key7 := tt.RequestAuthPost[keyobj](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys", data.UID), gin.H{
"all_channels": false, "all_channels": false,
"channels": []string{chanid}, "channels": []string{chanid},
"name": "TKey7", "name": "TKey7",
@ -462,22 +462,22 @@ func TestTokenKeysPermissions(t *testing.T) {
tt.RequestPostShouldFail(t, baseUrl, "/", gin.H{ tt.RequestPostShouldFail(t, baseUrl, "/", gin.H{
"key": key7.Token, "key": key7.Token,
"user_id": data.UserID, "user_id": data.UID,
"channel": "testchan2", "channel": "testchan2",
"title": "HelloWorld_001", "title": "HelloWorld_001",
}, 401, apierr.USER_AUTH_FAILED) // wrong channel }, 401, apierr.USER_AUTH_FAILED) // wrong channel
tt.RequestPostShouldFail(t, baseUrl, "/", gin.H{ tt.RequestPostShouldFail(t, baseUrl, "/", gin.H{
"key": key7.Token, "key": key7.Token,
"user_id": data.UserID, "user_id": data.UID,
"title": "HelloWorld_001", "title": "HelloWorld_001",
}, 401, apierr.USER_AUTH_FAILED) // no channel (=main) }, 401, apierr.USER_AUTH_FAILED) // no channel (=main)
tt.RequestAuthGetShouldFail(t, key7.Token, baseUrl, fmt.Sprintf("/api/v2/users/%s", data.UserID), 401, apierr.USER_AUTH_FAILED) // no user read perm tt.RequestAuthGetShouldFail(t, key7.Token, baseUrl, fmt.Sprintf("/api/v2/users/%s", data.UID), 401, apierr.USER_AUTH_FAILED) // no user read perm
tt.RequestAuthPatchShouldFail(t, key7.Token, baseUrl, "/api/v2/users/"+data.UserID, gin.H{"username": "my_user_001"}, 401, apierr.USER_AUTH_FAILED) // no user update perm tt.RequestAuthPatchShouldFail(t, key7.Token, baseUrl, "/api/v2/users/"+data.UID, gin.H{"username": "my_user_001"}, 401, apierr.USER_AUTH_FAILED) // no user update perm
key8 := tt.RequestAuthPost[keyobj](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys", data.UserID), gin.H{ key8 := tt.RequestAuthPost[keyobj](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys", data.UID), gin.H{
"all_channels": true, "all_channels": true,
"channels": []string{}, "channels": []string{},
"name": "TKey7", "name": "TKey7",
@ -486,7 +486,7 @@ func TestTokenKeysPermissions(t *testing.T) {
tt.RequestPostShouldFail(t, baseUrl, "/", gin.H{ tt.RequestPostShouldFail(t, baseUrl, "/", gin.H{
"key": key8.Token, "key": key8.Token,
"user_id": data.UserID, "user_id": data.UID,
"title": "HelloWorld_001", "title": "HelloWorld_001",
}, 401, apierr.USER_AUTH_FAILED) // no send perm }, 401, apierr.USER_AUTH_FAILED) // no send perm

View File

@ -1412,13 +1412,13 @@ func TestSendWithAdminKey(t *testing.T) {
Subscriptions []subobj `json:"subscriptions"` Subscriptions []subobj `json:"subscriptions"`
} }
chan1 := tt.RequestAuthPost[chanobj](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels", data1.UserID), gin.H{ chan1 := tt.RequestAuthPost[chanobj](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels", data1.UID), gin.H{
"name": "Chan1", "name": "Chan1",
}) })
chan2 := tt.RequestAuthPost[chanobj](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels", data1.UserID), gin.H{ chan2 := tt.RequestAuthPost[chanobj](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels", data1.UID), gin.H{
"name": "Chan2", "name": "Chan2",
}) })
chan3 := tt.RequestAuthPost[chanobj](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels", data1.UserID), gin.H{ chan3 := tt.RequestAuthPost[chanobj](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels", data1.UID), gin.H{
"name": "Chan3", "name": "Chan3",
}) })
@ -1428,21 +1428,21 @@ func TestSendWithAdminKey(t *testing.T) {
tt.RequestPost[gin.H](t, baseUrl, "/", gin.H{ tt.RequestPost[gin.H](t, baseUrl, "/", gin.H{
"key": data1.AdminKey, "key": data1.AdminKey,
"user_id": data1.UserID, "user_id": data1.UID,
"channel": "Chan1", "channel": "Chan1",
"title": tt.LipsumWord(1001, 1), "title": tt.LipsumWord(1001, 1),
}) })
tt.RequestPost[gin.H](t, baseUrl, "/", gin.H{ tt.RequestPost[gin.H](t, baseUrl, "/", gin.H{
"key": data1.AdminKey, "key": data1.AdminKey,
"user_id": data1.UserID, "user_id": data1.UID,
"channel": "Chan2", "channel": "Chan2",
"title": tt.LipsumWord(1001, 1), "title": tt.LipsumWord(1001, 1),
}) })
tt.RequestPost[gin.H](t, baseUrl, "/", gin.H{ tt.RequestPost[gin.H](t, baseUrl, "/", gin.H{
"key": data1.AdminKey, "key": data1.AdminKey,
"user_id": data1.UserID, "user_id": data1.UID,
"channel": "Chan3", "channel": "Chan3",
"title": tt.LipsumWord(1001, 1), "title": tt.LipsumWord(1001, 1),
}) })
@ -1487,13 +1487,13 @@ func TestSendWithSendKey(t *testing.T) {
Subscriptions []subobj `json:"subscriptions"` Subscriptions []subobj `json:"subscriptions"`
} }
chan1 := tt.RequestAuthPost[chanobj](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels", data1.UserID), gin.H{ chan1 := tt.RequestAuthPost[chanobj](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels", data1.UID), gin.H{
"name": "Chan1", "name": "Chan1",
}) })
chan2 := tt.RequestAuthPost[chanobj](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels", data1.UserID), gin.H{ chan2 := tt.RequestAuthPost[chanobj](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels", data1.UID), gin.H{
"name": "Chan2", "name": "Chan2",
}) })
chan3 := tt.RequestAuthPost[chanobj](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels", data1.UserID), gin.H{ chan3 := tt.RequestAuthPost[chanobj](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels", data1.UID), gin.H{
"name": "Chan3", "name": "Chan3",
}) })
@ -1503,21 +1503,21 @@ func TestSendWithSendKey(t *testing.T) {
tt.RequestPost[gin.H](t, baseUrl, "/", gin.H{ tt.RequestPost[gin.H](t, baseUrl, "/", gin.H{
"key": data1.SendKey, "key": data1.SendKey,
"user_id": data1.UserID, "user_id": data1.UID,
"channel": "Chan1", "channel": "Chan1",
"title": tt.LipsumWord(1001, 1), "title": tt.LipsumWord(1001, 1),
}) })
tt.RequestPost[gin.H](t, baseUrl, "/", gin.H{ tt.RequestPost[gin.H](t, baseUrl, "/", gin.H{
"key": data1.SendKey, "key": data1.SendKey,
"user_id": data1.UserID, "user_id": data1.UID,
"channel": "Chan2", "channel": "Chan2",
"title": tt.LipsumWord(1001, 1), "title": tt.LipsumWord(1001, 1),
}) })
tt.RequestPost[gin.H](t, baseUrl, "/", gin.H{ tt.RequestPost[gin.H](t, baseUrl, "/", gin.H{
"key": data1.SendKey, "key": data1.SendKey,
"user_id": data1.UserID, "user_id": data1.UID,
"channel": "Chan3", "channel": "Chan3",
"title": tt.LipsumWord(1001, 1), "title": tt.LipsumWord(1001, 1),
}) })
@ -1562,13 +1562,13 @@ func TestSendWithReadKey(t *testing.T) {
Subscriptions []subobj `json:"subscriptions"` Subscriptions []subobj `json:"subscriptions"`
} }
chan1 := tt.RequestAuthPost[chanobj](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels", data1.UserID), gin.H{ chan1 := tt.RequestAuthPost[chanobj](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels", data1.UID), gin.H{
"name": "Chan1", "name": "Chan1",
}) })
chan2 := tt.RequestAuthPost[chanobj](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels", data1.UserID), gin.H{ chan2 := tt.RequestAuthPost[chanobj](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels", data1.UID), gin.H{
"name": "Chan2", "name": "Chan2",
}) })
chan3 := tt.RequestAuthPost[chanobj](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels", data1.UserID), gin.H{ chan3 := tt.RequestAuthPost[chanobj](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels", data1.UID), gin.H{
"name": "Chan3", "name": "Chan3",
}) })
@ -1578,21 +1578,21 @@ func TestSendWithReadKey(t *testing.T) {
tt.RequestPostShouldFail(t, baseUrl, "/", gin.H{ tt.RequestPostShouldFail(t, baseUrl, "/", gin.H{
"key": data1.ReadKey, "key": data1.ReadKey,
"user_id": data1.UserID, "user_id": data1.UID,
"channel": "Chan1", "channel": "Chan1",
"title": tt.LipsumWord(1001, 1), "title": tt.LipsumWord(1001, 1),
}, 401, apierr.USER_AUTH_FAILED) }, 401, apierr.USER_AUTH_FAILED)
tt.RequestPostShouldFail(t, baseUrl, "/", gin.H{ tt.RequestPostShouldFail(t, baseUrl, "/", gin.H{
"key": data1.ReadKey, "key": data1.ReadKey,
"user_id": data1.UserID, "user_id": data1.UID,
"channel": "Chan2", "channel": "Chan2",
"title": tt.LipsumWord(1002, 1), "title": tt.LipsumWord(1002, 1),
}, 401, apierr.USER_AUTH_FAILED) }, 401, apierr.USER_AUTH_FAILED)
tt.RequestPostShouldFail(t, baseUrl, "/", gin.H{ tt.RequestPostShouldFail(t, baseUrl, "/", gin.H{
"key": data1.ReadKey, "key": data1.ReadKey,
"user_id": data1.UserID, "user_id": data1.UID,
"channel": "Chan3", "channel": "Chan3",
"title": tt.LipsumWord(1003, 1), "title": tt.LipsumWord(1003, 1),
}, 401, apierr.USER_AUTH_FAILED) }, 401, apierr.USER_AUTH_FAILED)
@ -1647,16 +1647,16 @@ func TestSendWithPermissionSendKey(t *testing.T) {
Token string `json:"token"` // only in create Token string `json:"token"` // only in create
} }
chan1 := tt.RequestAuthPost[chanobj](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels", data1.UserID), gin.H{ chan1 := tt.RequestAuthPost[chanobj](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels", data1.UID), gin.H{
"name": "Chan1", "name": "Chan1",
}) })
chan2 := tt.RequestAuthPost[chanobj](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels", data1.UserID), gin.H{ chan2 := tt.RequestAuthPost[chanobj](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels", data1.UID), gin.H{
"name": "Chan2", "name": "Chan2",
}) })
chan3 := tt.RequestAuthPost[chanobj](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels", data1.UserID), gin.H{ chan3 := tt.RequestAuthPost[chanobj](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels", data1.UID), gin.H{
"name": "Chan3", "name": "Chan3",
}) })
chan4 := tt.RequestAuthPost[chanobj](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels", data1.UserID), gin.H{ chan4 := tt.RequestAuthPost[chanobj](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels", data1.UID), gin.H{
"name": "Chan4", "name": "Chan4",
}) })
@ -1666,7 +1666,7 @@ func TestSendWithPermissionSendKey(t *testing.T) {
tt.AssertNotDefault(t, "chan4", chan4) tt.AssertNotDefault(t, "chan4", chan4)
{ {
keyOK := tt.RequestAuthPost[keyobj](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys", data1.UserID), gin.H{ keyOK := tt.RequestAuthPost[keyobj](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys", data1.UID), gin.H{
"all_channels": false, "all_channels": false,
"channels": []string{chan1.ChannelId, chan2.ChannelId, chan3.ChannelId}, "channels": []string{chan1.ChannelId, chan2.ChannelId, chan3.ChannelId},
"name": "K2", "name": "K2",
@ -1675,28 +1675,28 @@ func TestSendWithPermissionSendKey(t *testing.T) {
tt.RequestPost[gin.H](t, baseUrl, "/", gin.H{ tt.RequestPost[gin.H](t, baseUrl, "/", gin.H{
"key": keyOK.Token, "key": keyOK.Token,
"user_id": data1.UserID, "user_id": data1.UID,
"channel": "Chan1", "channel": "Chan1",
"title": tt.LipsumWord(1001, 1), "title": tt.LipsumWord(1001, 1),
}) })
tt.RequestPost[gin.H](t, baseUrl, "/", gin.H{ tt.RequestPost[gin.H](t, baseUrl, "/", gin.H{
"key": keyOK.Token, "key": keyOK.Token,
"user_id": data1.UserID, "user_id": data1.UID,
"channel": "Chan2", "channel": "Chan2",
"title": tt.LipsumWord(1002, 1), "title": tt.LipsumWord(1002, 1),
}) })
tt.RequestPost[gin.H](t, baseUrl, "/", gin.H{ tt.RequestPost[gin.H](t, baseUrl, "/", gin.H{
"key": keyOK.Token, "key": keyOK.Token,
"user_id": data1.UserID, "user_id": data1.UID,
"channel": "Chan3", "channel": "Chan3",
"title": tt.LipsumWord(1003, 1), "title": tt.LipsumWord(1003, 1),
}) })
} }
{ {
keyNOK := tt.RequestAuthPost[keyobj](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys", data1.UserID), gin.H{ keyNOK := tt.RequestAuthPost[keyobj](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys", data1.UID), gin.H{
"all_channels": false, "all_channels": false,
"channels": []string{}, "channels": []string{},
"name": "K3", "name": "K3",
@ -1705,28 +1705,28 @@ func TestSendWithPermissionSendKey(t *testing.T) {
tt.RequestPostShouldFail(t, baseUrl, "/", gin.H{ tt.RequestPostShouldFail(t, baseUrl, "/", gin.H{
"key": keyNOK.Token, "key": keyNOK.Token,
"user_id": data1.UserID, "user_id": data1.UID,
"channel": "Chan1", "channel": "Chan1",
"title": tt.LipsumWord(1001, 1), "title": tt.LipsumWord(1001, 1),
}, 401, apierr.USER_AUTH_FAILED) }, 401, apierr.USER_AUTH_FAILED)
tt.RequestPostShouldFail(t, baseUrl, "/", gin.H{ tt.RequestPostShouldFail(t, baseUrl, "/", gin.H{
"key": keyNOK.Token, "key": keyNOK.Token,
"user_id": data1.UserID, "user_id": data1.UID,
"channel": "Chan2", "channel": "Chan2",
"title": tt.LipsumWord(1002, 1), "title": tt.LipsumWord(1002, 1),
}, 401, apierr.USER_AUTH_FAILED) }, 401, apierr.USER_AUTH_FAILED)
tt.RequestPostShouldFail(t, baseUrl, "/", gin.H{ tt.RequestPostShouldFail(t, baseUrl, "/", gin.H{
"key": keyNOK.Token, "key": keyNOK.Token,
"user_id": data1.UserID, "user_id": data1.UID,
"channel": "Chan3", "channel": "Chan3",
"title": tt.LipsumWord(1003, 1), "title": tt.LipsumWord(1003, 1),
}, 401, apierr.USER_AUTH_FAILED) }, 401, apierr.USER_AUTH_FAILED)
} }
{ {
keyNOK := tt.RequestAuthPost[keyobj](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys", data1.UserID), gin.H{ keyNOK := tt.RequestAuthPost[keyobj](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys", data1.UID), gin.H{
"all_channels": false, "all_channels": false,
"channels": []string{chan4.ChannelId}, "channels": []string{chan4.ChannelId},
"name": "K4", "name": "K4",
@ -1735,28 +1735,28 @@ func TestSendWithPermissionSendKey(t *testing.T) {
tt.RequestPostShouldFail(t, baseUrl, "/", gin.H{ tt.RequestPostShouldFail(t, baseUrl, "/", gin.H{
"key": keyNOK.Token, "key": keyNOK.Token,
"user_id": data1.UserID, "user_id": data1.UID,
"channel": "Chan1", "channel": "Chan1",
"title": tt.LipsumWord(1001, 1), "title": tt.LipsumWord(1001, 1),
}, 401, apierr.USER_AUTH_FAILED) }, 401, apierr.USER_AUTH_FAILED)
tt.RequestPostShouldFail(t, baseUrl, "/", gin.H{ tt.RequestPostShouldFail(t, baseUrl, "/", gin.H{
"key": keyNOK.Token, "key": keyNOK.Token,
"user_id": data1.UserID, "user_id": data1.UID,
"channel": "Chan2", "channel": "Chan2",
"title": tt.LipsumWord(1002, 1), "title": tt.LipsumWord(1002, 1),
}, 401, apierr.USER_AUTH_FAILED) }, 401, apierr.USER_AUTH_FAILED)
tt.RequestPostShouldFail(t, baseUrl, "/", gin.H{ tt.RequestPostShouldFail(t, baseUrl, "/", gin.H{
"key": keyNOK.Token, "key": keyNOK.Token,
"user_id": data1.UserID, "user_id": data1.UID,
"channel": "Chan3", "channel": "Chan3",
"title": tt.LipsumWord(1003, 1), "title": tt.LipsumWord(1003, 1),
}, 401, apierr.USER_AUTH_FAILED) }, 401, apierr.USER_AUTH_FAILED)
} }
{ {
keyNOK := tt.RequestAuthPost[keyobj](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys", data1.UserID), gin.H{ keyNOK := tt.RequestAuthPost[keyobj](t, data1.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys", data1.UID), gin.H{
"all_channels": false, "all_channels": false,
"channels": []string{chan1.ChannelId, chan2.ChannelId, chan3.ChannelId}, "channels": []string{chan1.ChannelId, chan2.ChannelId, chan3.ChannelId},
"name": "K4", "name": "K4",
@ -1765,21 +1765,21 @@ func TestSendWithPermissionSendKey(t *testing.T) {
tt.RequestPostShouldFail(t, baseUrl, "/", gin.H{ tt.RequestPostShouldFail(t, baseUrl, "/", gin.H{
"key": keyNOK.Token, "key": keyNOK.Token,
"user_id": data1.UserID, "user_id": data1.UID,
"channel": "Chan1", "channel": "Chan1",
"title": tt.LipsumWord(1001, 1), "title": tt.LipsumWord(1001, 1),
}, 401, apierr.USER_AUTH_FAILED) }, 401, apierr.USER_AUTH_FAILED)
tt.RequestPostShouldFail(t, baseUrl, "/", gin.H{ tt.RequestPostShouldFail(t, baseUrl, "/", gin.H{
"key": keyNOK.Token, "key": keyNOK.Token,
"user_id": data1.UserID, "user_id": data1.UID,
"channel": "Chan2", "channel": "Chan2",
"title": tt.LipsumWord(1002, 1), "title": tt.LipsumWord(1002, 1),
}, 401, apierr.USER_AUTH_FAILED) }, 401, apierr.USER_AUTH_FAILED)
tt.RequestPostShouldFail(t, baseUrl, "/", gin.H{ tt.RequestPostShouldFail(t, baseUrl, "/", gin.H{
"key": keyNOK.Token, "key": keyNOK.Token,
"user_id": data1.UserID, "user_id": data1.UID,
"channel": "Chan3", "channel": "Chan3",
"title": tt.LipsumWord(1003, 1), "title": tt.LipsumWord(1003, 1),
}, 401, apierr.USER_AUTH_FAILED) }, 401, apierr.USER_AUTH_FAILED)

File diff suppressed because it is too large Load Diff

View File

@ -422,7 +422,7 @@ func InitDefaultData(t *testing.T, ws *logic.Application) DefData {
} }
type SingleData struct { type SingleData struct {
UserID string UID string
AdminKey string AdminKey string
SendKey string SendKey string
ReadKey string ReadKey string
@ -464,7 +464,7 @@ func InitSingleData(t *testing.T, ws *logic.Application) SingleData {
success = true success = true
return SingleData{ return SingleData{
UserID: r0.UserId, UID: r0.UserId,
AdminKey: r0.AdminKey, AdminKey: r0.AdminKey,
SendKey: r0.SendKey, SendKey: r0.SendKey,
ReadKey: r0.ReadKey, ReadKey: r0.ReadKey,