mirror of
https://github.com/absmach/supermq.git
synced 2026-06-23 06:40:19 +00:00
NOISSUE - Update auth in journal service (#2527)
Signed-off-by: Felix Gateru <felix.gateru@gmail.com>
This commit is contained in:
+12
-6
@@ -9,24 +9,30 @@ import (
|
||||
)
|
||||
|
||||
var cmdJournal = cobra.Command{
|
||||
Use: "get <entity_type> <entity_id> <user_auth_token>",
|
||||
Use: "get <entity_type> <entity_id> <domain_id> <user_auth_token>",
|
||||
Short: "Get journal",
|
||||
Long: "Get journal\n" +
|
||||
"Usage:\n" +
|
||||
"\tmagistrala-cli journal get <entity_type> <entity_id> <user_auth_token> - lists journal logs\n" +
|
||||
"\tmagistrala-cli journal get <entity_type> <entity_id> <user_auth_token> --offset <offset> --limit <limit> - lists journal logs with provided offset and limit\n",
|
||||
"\tmagistrala-cli journal get user <user_id> <user_auth_token> - lists user journal logs\n" +
|
||||
"\tmagistrala-cli journal get <entity_type> <entity_id> <domain_id> <user_auth_token> - lists entity journal logs\n" +
|
||||
"\tmagistrala-cli journal get <entity_type> <entity_id> <domain_id> <user_auth_token> --offset <offset> --limit <limit> - lists user journal logs with provided offset and limit\n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 3 {
|
||||
if len(args) < 3 || len(args) > 4 {
|
||||
logUsageCmd(*cmd, cmd.Use)
|
||||
return
|
||||
}
|
||||
|
||||
pageMetadata := mgxsdk.PageMetadata{
|
||||
Offset: Offset,
|
||||
Limit: Limit,
|
||||
}
|
||||
|
||||
journal, err := sdk.Journal(args[0], args[1], pageMetadata, args[2])
|
||||
entityType, entityID, token := args[0], args[1], args[2]
|
||||
domainID := ""
|
||||
if len(args) == 4 {
|
||||
entityType, entityID, domainID, token = args[0], args[1], args[2], args[3]
|
||||
}
|
||||
|
||||
journal, err := sdk.Journal(entityType, entityID, domainID, pageMetadata, token)
|
||||
if err != nil {
|
||||
logErrorCmd(*cmd, err)
|
||||
return
|
||||
|
||||
+26
-5
@@ -31,8 +31,9 @@ func TestGetJournalCmd(t *testing.T) {
|
||||
rootCmd := setFlags(invCmd)
|
||||
|
||||
var page mgsdk.JournalsPage
|
||||
entityType := "entity_type"
|
||||
entityId := journal.ID
|
||||
entityType := "group"
|
||||
entityId := testsutil.GenerateUUID(t)
|
||||
domainId := testsutil.GenerateUUID(t)
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -43,10 +44,26 @@ func TestGetJournalCmd(t *testing.T) {
|
||||
errLogMessage string
|
||||
}{
|
||||
{
|
||||
desc: "get journal with journal id",
|
||||
desc: "get user journal",
|
||||
args: []string{
|
||||
"user",
|
||||
entityId,
|
||||
token,
|
||||
},
|
||||
logType: entityLog,
|
||||
page: mgsdk.JournalsPage{
|
||||
Total: 1,
|
||||
Offset: 0,
|
||||
Limit: 10,
|
||||
Journals: []mgsdk.Journal{journal},
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "get group journal",
|
||||
args: []string{
|
||||
entityType,
|
||||
entityId,
|
||||
domainId,
|
||||
token,
|
||||
},
|
||||
logType: entityLog,
|
||||
@@ -63,6 +80,7 @@ func TestGetJournalCmd(t *testing.T) {
|
||||
entityType,
|
||||
entityId,
|
||||
token,
|
||||
domainId,
|
||||
extraArg,
|
||||
},
|
||||
logType: usageLog,
|
||||
@@ -72,6 +90,7 @@ func TestGetJournalCmd(t *testing.T) {
|
||||
args: []string{
|
||||
entityType,
|
||||
entityId,
|
||||
domainId,
|
||||
invalidToken,
|
||||
},
|
||||
logType: errLog,
|
||||
@@ -82,8 +101,10 @@ func TestGetJournalCmd(t *testing.T) {
|
||||
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
sdkCall := sdkMock.On("Journal", tc.args[0], tc.args[1], mock.Anything, tc.args[2]).Return(tc.page, tc.sdkErr)
|
||||
|
||||
sdkCall := sdkMock.On("Journal", tc.args[0], tc.args[1], "", mock.Anything, tc.args[2]).Return(tc.page, tc.sdkErr)
|
||||
if tc.args[0] != "user" {
|
||||
sdkCall = sdkMock.On("Journal", tc.args[0], tc.args[1], tc.args[2], mock.Anything, tc.args[3]).Return(tc.page, tc.sdkErr)
|
||||
}
|
||||
out := executeCommand(t, rootCmd, append([]string{getCmd}, tc.args...)...)
|
||||
|
||||
switch tc.logType {
|
||||
|
||||
Reference in New Issue
Block a user