2023-06-14 12:40:37 +02:00
|
|
|
// Copyright (c) Mainflux
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2022-11-21 14:40:19 +01:00
|
|
|
package mqtt_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2023-05-31 13:30:28 +03:00
|
|
|
"context"
|
2022-11-21 14:40:19 +01:00
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"testing"
|
|
|
|
|
NOISSUE - Switch to Google Zanzibar Access control approach (#1919)
* Return Auth service
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Update Compose to run with SpiceDB and Auth svc
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Update auth gRPC API
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Remove Users' policies
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Move Groups to internal
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Use shared groups in Users
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Remove unused code
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Use pkg Groups in Things
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Remove Things groups
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Make imports consistent
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Update Groups networking
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Remove things groups-specific API
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Move Things Clients to the root
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Move Clients to Users root
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Temporarily remove tracing
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Fix imports
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Add buffer config for gRPC
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Update auth type for Things
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Use Auth for login
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Add temporary solution for refresh token
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Update Tokenizer interface
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Updade tokens issuing
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Fix token issuing
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Update JWT validator and refactor Tokenizer
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Rename access timeout
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Rename login to authenticate
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Update Identify to use SubjectID
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Add Auth to Groups
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Use the Auth service for Groups
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Update auth schema
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Fix Auth for Groups
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Add auth for addons (#14)
Signed-off-by: Arvindh <arvindh91@gmail.com>
Speparate Login and Refresh tokens
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Merge authN and authZ requests for things
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Add connect and disconnect
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Update sharing
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Fix policies addition and removal
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Update relation with roels
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Add gRPC to Things
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Assign and Unassign members to group and Listing of Group members (#15)
* add auth for addons
Signed-off-by: Arvindh <arvindh91@gmail.com>
* add assign and unassign to group
Signed-off-by: Arvindh <arvindh91@gmail.com>
* add group incomplete repo implementation
Signed-off-by: Arvindh <arvindh91@gmail.com>
* groups for users
Signed-off-by: Arvindh <arvindh91@gmail.com>
* groups for users
Signed-off-by: Arvindh <arvindh91@gmail.com>
* groups for users
Signed-off-by: Arvindh <arvindh91@gmail.com>
* groups for users
Signed-off-by: Arvindh <arvindh91@gmail.com>
---------
Signed-off-by: Arvindh <arvindh91@gmail.com>
Move coap mqtt and ws policies to spicedb (#16)
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
Remove old policies
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
NOISSUE - Things authorize to return thingID (#18)
This commit modifies the authorize endpoint to the grpc endpoint to return thingID. The authorize endpoint allows adapters to get the publisher of the message.
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
Add Groups to users service (#17)
* add assign and unassign to group
Signed-off-by: Arvindh <arvindh91@gmail.com>
* add group incomplete repo implementation
Signed-off-by: Arvindh <arvindh91@gmail.com>
* groups for users
Signed-off-by: Arvindh <arvindh91@gmail.com>
* groups for users
Signed-off-by: Arvindh <arvindh91@gmail.com>
* groups for users
Signed-off-by: Arvindh <arvindh91@gmail.com>
* groups for users
Signed-off-by: Arvindh <arvindh91@gmail.com>
* groups for users stable 1
Signed-off-by: Arvindh <arvindh91@gmail.com>
* groups for users stable 2
Signed-off-by: Arvindh <arvindh91@gmail.com>
* groups for users & things
Signed-off-by: Arvindh <arvindh91@gmail.com>
* Amend signature
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix merge error
Signed-off-by: Arvindh <arvindh91@gmail.com>
---------
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
* NOISSUE - Fix es code (#21)
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
* NOISSUE - Fix Bugs (#20)
* fix bugs
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix bugs
Signed-off-by: Arvindh <arvindh91@gmail.com>
---------
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
* NOISSUE - Test e2e (#19)
* fix: connect method
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
* fix: e2e
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
* fix changes in sdk and e2e
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
* feat(docker): remove unnecessary port mapping
Remove the port mapping for MQTT broker in the docker-compose.yml file.
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
* Enable group listing
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
* feat(responses): update ChannelsPage struct
The ChannelsPage struct in the responses.go file has been updated. The "Channels" field has been renamed to "Groups" to provide more accurate naming. This change ensures consistency and clarity in the codebase.
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
* feat(things): add UpdateClientSecret method
Add the UpdateClientSecret method to the things service. This method allows updating the client secret for a specific client identified by the provided token, id, and key parameters.
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
---------
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
* Use smaller buffers for gRPC
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
* Clean up tests (#22)
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
* Add Connect Disconnect endpoints (#23)
* fix bugs
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix bugs
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix list of things in a channel and Add connect disconnect endpoint
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix list of things in a channel and Add connect disconnect endpoint
Signed-off-by: Arvindh <arvindh91@gmail.com>
---------
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
* Add: Things share with users (#25)
* fix list of things in a channel and Add connect disconnect endpoint
Signed-off-by: Arvindh <arvindh91@gmail.com>
* add: things share with other users
Signed-off-by: Arvindh <arvindh91@gmail.com>
---------
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
* NOISSUE - Rename gRPC Services (#24)
* Rename things and users auth service
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
* docs: add authorization docs for gRPC services
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
* Rename things and users grpc services
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
* Remove mainflux.env package
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
---------
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
* Add: Listing of things, channels, groups, users (#26)
* add: listing of channels, users, groups, things
Signed-off-by: Arvindh <arvindh91@gmail.com>
* add: listing of channels, users, groups, things
Signed-off-by: Arvindh <arvindh91@gmail.com>
* add: listing of channels, users, groups, things
Signed-off-by: Arvindh <arvindh91@gmail.com>
* add: listing of channels, users, groups, things
Signed-off-by: Arvindh <arvindh91@gmail.com>
---------
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
* NOISSUE - Clean Up Users (#27)
* feat(groups): rename redis package to events
- Renamed the `redis` package to `events` in the `internal/groups` directory.
- Updated the file paths and names accordingly.
- This change reflects the more accurate purpose of the package and improves code organization.
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
* feat(auth): Modify identity method
Change request and response of identity method
Add accessToken and refreshToken to Token response
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
* clean up users, remove dead code
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
* feat(users): add unit tests for user service
This commit adds unit tests for the user service in the `users` package. The tests cover various scenarios and ensure the correct behavior of the service.
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
---------
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
* Add: List of user groups & removed repeating code in groups (#29)
* removed repeating code in list groups
Signed-off-by: Arvindh <arvindh91@gmail.com>
* add: list of user group
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix: otel handler operator name for endpoints
Signed-off-by: Arvindh <arvindh91@gmail.com>
---------
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
* NOISSUE - Clean Up Things Service (#28)
* Rework things service
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
* add tests
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
---------
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
* NOISSUE - Clean Up Auth Service (#30)
* clean up auth service
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
* feat(auth): remove unused import
Remove the unused import of `emptypb` in `auth.pb.go`. This import is not being used in the codebase and can be safely removed.
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
---------
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
* NOISSUE - Update API docs (#31)
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
* Remove TODO comments and cleanup the code
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
* Update dependenices
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
---------
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
Co-authored-by: b1ackd0t <28790446+rodneyosodo@users.noreply.github.com>
Co-authored-by: Arvindh <30824765+arvindh123@users.noreply.github.com>
2023-10-15 22:02:13 +02:00
|
|
|
authmocks "github.com/mainflux/mainflux/auth/mocks"
|
2022-11-21 14:40:19 +01:00
|
|
|
"github.com/mainflux/mainflux/logger"
|
|
|
|
"github.com/mainflux/mainflux/mqtt"
|
|
|
|
"github.com/mainflux/mainflux/mqtt/mocks"
|
|
|
|
"github.com/mainflux/mainflux/pkg/errors"
|
|
|
|
"github.com/mainflux/mproxy/pkg/session"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
thingID = "513d02d2-16c1-4f23-98be-9e12f8fee898"
|
2023-06-14 12:40:37 +02:00
|
|
|
thingID1 = "513d02d2-16c1-4f23-98be-9e12f8fee899"
|
|
|
|
password = "password"
|
|
|
|
password1 = "password1"
|
2022-11-21 14:40:19 +01:00
|
|
|
chanID = "123e4567-e89b-12d3-a456-000000000001"
|
|
|
|
invalidID = "invalidID"
|
|
|
|
clientID = "clientID"
|
2023-06-14 12:40:37 +02:00
|
|
|
clientID1 = "clientID1"
|
2022-11-21 14:40:19 +01:00
|
|
|
subtopic = "testSubtopic"
|
|
|
|
invalidChannelIDTopic = "channels/**/messages"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
topicMsg = "channels/%s/messages"
|
|
|
|
topic = fmt.Sprintf(topicMsg, chanID)
|
|
|
|
invalidTopic = "invalidTopic"
|
|
|
|
payload = []byte("[{'n':'test-name', 'v': 1.2}]")
|
|
|
|
topics = []string{topic}
|
|
|
|
invalidTopics = []string{invalidTopic}
|
|
|
|
invalidChanIDTopics = []string{fmt.Sprintf(topicMsg, invalidTopic)}
|
2023-07-28 04:01:27 +03:00
|
|
|
// Test log messages for cases the handler does not provide a return value.
|
2022-11-21 14:40:19 +01:00
|
|
|
logBuffer = bytes.Buffer{}
|
2023-05-31 13:30:28 +03:00
|
|
|
sessionClient = session.Session{
|
2022-11-21 14:40:19 +01:00
|
|
|
ID: clientID,
|
|
|
|
Username: thingID,
|
|
|
|
Password: []byte(password),
|
|
|
|
}
|
2023-06-14 12:40:37 +02:00
|
|
|
sessionClientSub = session.Session{
|
|
|
|
ID: clientID1,
|
|
|
|
Username: thingID1,
|
|
|
|
Password: []byte(password1),
|
|
|
|
}
|
2023-05-31 13:30:28 +03:00
|
|
|
invalidThingSessionClient = session.Session{
|
2022-11-21 14:40:19 +01:00
|
|
|
ID: clientID,
|
|
|
|
Username: invalidID,
|
|
|
|
Password: []byte(password),
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAuthConnect(t *testing.T) {
|
|
|
|
handler := newHandler()
|
|
|
|
|
|
|
|
cases := []struct {
|
|
|
|
desc string
|
|
|
|
err error
|
2023-05-31 13:30:28 +03:00
|
|
|
session *session.Session
|
2022-11-21 14:40:19 +01:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
desc: "connect without active session",
|
|
|
|
err: mqtt.ErrClientNotInitialized,
|
|
|
|
session: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "connect without clientID",
|
|
|
|
err: mqtt.ErrMissingClientID,
|
2023-05-31 13:30:28 +03:00
|
|
|
session: &session.Session{
|
2022-11-21 14:40:19 +01:00
|
|
|
ID: "",
|
|
|
|
Username: thingID,
|
|
|
|
Password: []byte(password),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "connect with invalid password",
|
|
|
|
err: errors.ErrAuthentication,
|
2023-05-31 13:30:28 +03:00
|
|
|
session: &session.Session{
|
2022-11-21 14:40:19 +01:00
|
|
|
ID: clientID,
|
|
|
|
Username: thingID,
|
|
|
|
Password: []byte(""),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "connect with valid password and invalid username",
|
|
|
|
err: errors.ErrAuthentication,
|
|
|
|
session: &invalidThingSessionClient,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "connect with valid username and password",
|
|
|
|
err: nil,
|
|
|
|
session: &sessionClient,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range cases {
|
2023-05-31 13:30:28 +03:00
|
|
|
ctx := context.TODO()
|
|
|
|
if tc.session != nil {
|
|
|
|
ctx = session.NewContext(ctx, tc.session)
|
|
|
|
}
|
|
|
|
err := handler.AuthConnect(ctx)
|
2022-11-21 14:40:19 +01:00
|
|
|
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAuthPublish(t *testing.T) {
|
|
|
|
handler := newHandler()
|
|
|
|
|
|
|
|
cases := []struct {
|
|
|
|
desc string
|
2023-05-31 13:30:28 +03:00
|
|
|
session *session.Session
|
2022-11-21 14:40:19 +01:00
|
|
|
err error
|
|
|
|
topic *string
|
|
|
|
payload []byte
|
|
|
|
}{
|
|
|
|
{
|
2023-06-14 12:40:37 +02:00
|
|
|
desc: "publish with an inactive client",
|
2023-05-31 13:30:28 +03:00
|
|
|
session: nil,
|
2022-11-21 14:40:19 +01:00
|
|
|
err: mqtt.ErrClientNotInitialized,
|
|
|
|
topic: &topic,
|
|
|
|
payload: payload,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "publish without topic",
|
2023-05-31 13:30:28 +03:00
|
|
|
session: &sessionClient,
|
2022-11-21 14:40:19 +01:00
|
|
|
err: mqtt.ErrMissingTopicPub,
|
|
|
|
topic: nil,
|
|
|
|
payload: payload,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "publish with malformed topic",
|
2023-05-31 13:30:28 +03:00
|
|
|
session: &sessionClient,
|
2022-11-21 14:40:19 +01:00
|
|
|
err: mqtt.ErrMalformedTopic,
|
|
|
|
topic: &invalidTopic,
|
|
|
|
payload: payload,
|
|
|
|
},
|
2023-06-14 12:40:37 +02:00
|
|
|
{
|
|
|
|
desc: "publish with invalid access rights",
|
|
|
|
session: &sessionClientSub,
|
|
|
|
err: errors.ErrAuthorization,
|
|
|
|
topic: &topic,
|
|
|
|
payload: payload,
|
|
|
|
},
|
2022-11-21 14:40:19 +01:00
|
|
|
{
|
|
|
|
desc: "publish successfully",
|
2023-05-31 13:30:28 +03:00
|
|
|
session: &sessionClient,
|
2022-11-21 14:40:19 +01:00
|
|
|
err: nil,
|
|
|
|
topic: &topic,
|
|
|
|
payload: payload,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range cases {
|
2023-05-31 13:30:28 +03:00
|
|
|
ctx := context.TODO()
|
|
|
|
if tc.session != nil {
|
|
|
|
ctx = session.NewContext(ctx, tc.session)
|
|
|
|
}
|
|
|
|
err := handler.AuthPublish(ctx, tc.topic, &tc.payload)
|
2022-11-21 14:40:19 +01:00
|
|
|
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAuthSubscribe(t *testing.T) {
|
|
|
|
handler := newHandler()
|
|
|
|
|
|
|
|
cases := []struct {
|
2023-05-31 13:30:28 +03:00
|
|
|
desc string
|
|
|
|
session *session.Session
|
|
|
|
err error
|
|
|
|
topic *[]string
|
2022-11-21 14:40:19 +01:00
|
|
|
}{
|
|
|
|
{
|
2023-05-31 13:30:28 +03:00
|
|
|
desc: "subscribe without active session",
|
|
|
|
session: nil,
|
|
|
|
err: mqtt.ErrClientNotInitialized,
|
|
|
|
topic: &topics,
|
2022-11-21 14:40:19 +01:00
|
|
|
},
|
|
|
|
{
|
2023-05-31 13:30:28 +03:00
|
|
|
desc: "subscribe without topics",
|
|
|
|
session: &sessionClient,
|
|
|
|
err: mqtt.ErrMissingTopicSub,
|
|
|
|
topic: nil,
|
2022-11-21 14:40:19 +01:00
|
|
|
},
|
|
|
|
{
|
2023-05-31 13:30:28 +03:00
|
|
|
desc: "subscribe with invalid topics",
|
|
|
|
session: &sessionClient,
|
|
|
|
err: mqtt.ErrMalformedTopic,
|
|
|
|
topic: &invalidTopics,
|
2022-11-21 14:40:19 +01:00
|
|
|
},
|
|
|
|
{
|
2023-05-31 13:30:28 +03:00
|
|
|
desc: "subscribe with invalid channel ID",
|
|
|
|
session: &sessionClient,
|
2023-06-14 12:40:37 +02:00
|
|
|
err: errors.ErrAuthorization,
|
2023-05-31 13:30:28 +03:00
|
|
|
topic: &invalidChanIDTopics,
|
2022-11-21 14:40:19 +01:00
|
|
|
},
|
|
|
|
{
|
2023-06-14 12:40:37 +02:00
|
|
|
desc: "subscribe with active session, valid topics, but invalid access rights",
|
|
|
|
session: &sessionClient,
|
|
|
|
err: errors.ErrAuthorization,
|
2023-05-31 13:30:28 +03:00
|
|
|
topic: &topics,
|
2022-11-21 14:40:19 +01:00
|
|
|
},
|
|
|
|
{
|
2023-06-14 12:40:37 +02:00
|
|
|
desc: "subscribe successfully",
|
|
|
|
session: &sessionClientSub,
|
2023-05-31 13:30:28 +03:00
|
|
|
err: nil,
|
|
|
|
topic: &topics,
|
2022-11-21 14:40:19 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range cases {
|
2023-05-31 13:30:28 +03:00
|
|
|
ctx := context.TODO()
|
|
|
|
if tc.session != nil {
|
|
|
|
ctx = session.NewContext(ctx, tc.session)
|
|
|
|
}
|
|
|
|
err := handler.AuthSubscribe(ctx, tc.topic)
|
2022-11-21 14:40:19 +01:00
|
|
|
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConnect(t *testing.T) {
|
|
|
|
handler := newHandler()
|
|
|
|
logBuffer.Reset()
|
|
|
|
|
|
|
|
cases := []struct {
|
2023-05-31 13:30:28 +03:00
|
|
|
desc string
|
|
|
|
session *session.Session
|
2023-08-22 21:01:47 +03:00
|
|
|
err error
|
2023-05-31 13:30:28 +03:00
|
|
|
logMsg string
|
2022-11-21 14:40:19 +01:00
|
|
|
}{
|
|
|
|
{
|
2023-05-31 13:30:28 +03:00
|
|
|
desc: "connect without active session",
|
|
|
|
session: nil,
|
2023-08-22 21:01:47 +03:00
|
|
|
err: errors.Wrap(mqtt.ErrFailedConnect, mqtt.ErrClientNotInitialized),
|
2022-11-21 14:40:19 +01:00
|
|
|
},
|
|
|
|
{
|
2023-05-31 13:30:28 +03:00
|
|
|
desc: "connect with active session",
|
|
|
|
session: &sessionClient,
|
|
|
|
logMsg: fmt.Sprintf(mqtt.LogInfoConnected, clientID),
|
2023-08-22 21:01:47 +03:00
|
|
|
err: nil,
|
2022-11-21 14:40:19 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range cases {
|
2023-05-31 13:30:28 +03:00
|
|
|
ctx := context.TODO()
|
|
|
|
if tc.session != nil {
|
|
|
|
ctx = session.NewContext(ctx, tc.session)
|
|
|
|
}
|
2023-08-22 21:01:47 +03:00
|
|
|
err := handler.Connect(ctx)
|
2022-11-21 14:40:19 +01:00
|
|
|
assert.Contains(t, logBuffer.String(), tc.logMsg)
|
2023-08-22 21:01:47 +03:00
|
|
|
assert.Equal(t, tc.err, err)
|
2022-11-21 14:40:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPublish(t *testing.T) {
|
|
|
|
handler := newHandler()
|
|
|
|
logBuffer.Reset()
|
|
|
|
|
|
|
|
malformedSubtopics := topic + "/" + subtopic + "%"
|
|
|
|
wrongCharSubtopics := topic + "/" + subtopic + ">"
|
|
|
|
validSubtopic := topic + "/" + subtopic
|
|
|
|
|
|
|
|
cases := []struct {
|
|
|
|
desc string
|
2023-05-31 13:30:28 +03:00
|
|
|
session *session.Session
|
2022-11-21 14:40:19 +01:00
|
|
|
topic string
|
|
|
|
payload []byte
|
|
|
|
logMsg string
|
2023-08-22 21:01:47 +03:00
|
|
|
err error
|
2022-11-21 14:40:19 +01:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
desc: "publish without active session",
|
2023-05-31 13:30:28 +03:00
|
|
|
session: nil,
|
2022-11-21 14:40:19 +01:00
|
|
|
topic: topic,
|
|
|
|
payload: payload,
|
2023-08-22 21:01:47 +03:00
|
|
|
err: errors.Wrap(mqtt.ErrFailedPublish, mqtt.ErrClientNotInitialized),
|
2022-11-21 14:40:19 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "publish with invalid topic",
|
2023-05-31 13:30:28 +03:00
|
|
|
session: &sessionClient,
|
2022-11-21 14:40:19 +01:00
|
|
|
topic: invalidTopic,
|
|
|
|
payload: payload,
|
|
|
|
logMsg: fmt.Sprintf(mqtt.LogInfoPublished, clientID, invalidTopic),
|
2023-08-22 21:01:47 +03:00
|
|
|
err: errors.Wrap(mqtt.ErrFailedPublish, mqtt.ErrMalformedTopic),
|
2022-11-21 14:40:19 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "publish with invalid channel ID",
|
2023-05-31 13:30:28 +03:00
|
|
|
session: &sessionClient,
|
2022-11-21 14:40:19 +01:00
|
|
|
topic: invalidChannelIDTopic,
|
|
|
|
payload: payload,
|
2023-08-22 21:01:47 +03:00
|
|
|
err: errors.Wrap(mqtt.ErrFailedPublish, mqtt.ErrMalformedTopic),
|
2022-11-21 14:40:19 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "publish with malformed subtopic",
|
2023-05-31 13:30:28 +03:00
|
|
|
session: &sessionClient,
|
2022-11-21 14:40:19 +01:00
|
|
|
topic: malformedSubtopics,
|
|
|
|
payload: payload,
|
2023-08-22 21:01:47 +03:00
|
|
|
err: errors.Wrap(mqtt.ErrFailedParseSubtopic, mqtt.ErrMalformedSubtopic),
|
2022-11-21 14:40:19 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "publish with subtopic containing wrong character",
|
2023-05-31 13:30:28 +03:00
|
|
|
session: &sessionClient,
|
2022-11-21 14:40:19 +01:00
|
|
|
topic: wrongCharSubtopics,
|
|
|
|
payload: payload,
|
2023-08-22 21:01:47 +03:00
|
|
|
err: errors.Wrap(mqtt.ErrFailedParseSubtopic, mqtt.ErrMalformedSubtopic),
|
2022-11-21 14:40:19 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "publish with subtopic",
|
2023-05-31 13:30:28 +03:00
|
|
|
session: &sessionClient,
|
2022-11-21 14:40:19 +01:00
|
|
|
topic: validSubtopic,
|
|
|
|
payload: payload,
|
|
|
|
logMsg: subtopic,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "publish without subtopic",
|
2023-05-31 13:30:28 +03:00
|
|
|
session: &sessionClient,
|
2022-11-21 14:40:19 +01:00
|
|
|
topic: topic,
|
|
|
|
payload: payload,
|
|
|
|
logMsg: "",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range cases {
|
2023-05-31 13:30:28 +03:00
|
|
|
ctx := context.TODO()
|
|
|
|
if tc.session != nil {
|
|
|
|
ctx = session.NewContext(ctx, tc.session)
|
|
|
|
}
|
2023-08-22 21:01:47 +03:00
|
|
|
err := handler.Publish(ctx, &tc.topic, &tc.payload)
|
2022-11-21 14:40:19 +01:00
|
|
|
assert.Contains(t, logBuffer.String(), tc.logMsg)
|
2023-08-22 21:01:47 +03:00
|
|
|
assert.Equal(t, tc.err, err)
|
2022-11-21 14:40:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSubscribe(t *testing.T) {
|
|
|
|
handler := newHandler()
|
|
|
|
logBuffer.Reset()
|
|
|
|
|
|
|
|
cases := []struct {
|
2023-05-31 13:30:28 +03:00
|
|
|
desc string
|
|
|
|
session *session.Session
|
|
|
|
topic []string
|
|
|
|
logMsg string
|
2023-08-22 21:01:47 +03:00
|
|
|
err error
|
2022-11-21 14:40:19 +01:00
|
|
|
}{
|
|
|
|
{
|
2023-05-31 13:30:28 +03:00
|
|
|
desc: "subscribe without active session",
|
|
|
|
session: nil,
|
|
|
|
topic: topics,
|
2023-08-22 21:01:47 +03:00
|
|
|
err: errors.Wrap(mqtt.ErrFailedSubscribe, mqtt.ErrClientNotInitialized),
|
2022-11-21 14:40:19 +01:00
|
|
|
},
|
|
|
|
{
|
2023-05-31 13:30:28 +03:00
|
|
|
desc: "subscribe with valid session and topics",
|
|
|
|
session: &sessionClient,
|
|
|
|
topic: topics,
|
|
|
|
logMsg: fmt.Sprintf(mqtt.LogInfoSubscribed, clientID, topics[0]),
|
2022-11-21 14:40:19 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range cases {
|
2023-05-31 13:30:28 +03:00
|
|
|
ctx := context.TODO()
|
|
|
|
if tc.session != nil {
|
|
|
|
ctx = session.NewContext(ctx, tc.session)
|
|
|
|
}
|
2023-08-22 21:01:47 +03:00
|
|
|
err := handler.Subscribe(ctx, &tc.topic)
|
2022-11-21 14:40:19 +01:00
|
|
|
assert.Contains(t, logBuffer.String(), tc.logMsg)
|
2023-08-22 21:01:47 +03:00
|
|
|
assert.Equal(t, tc.err, err)
|
2022-11-21 14:40:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUnsubscribe(t *testing.T) {
|
|
|
|
handler := newHandler()
|
|
|
|
logBuffer.Reset()
|
|
|
|
|
|
|
|
cases := []struct {
|
2023-05-31 13:30:28 +03:00
|
|
|
desc string
|
|
|
|
session *session.Session
|
|
|
|
topic []string
|
|
|
|
logMsg string
|
2023-08-22 21:01:47 +03:00
|
|
|
err error
|
2022-11-21 14:40:19 +01:00
|
|
|
}{
|
|
|
|
{
|
2023-05-31 13:30:28 +03:00
|
|
|
desc: "unsubscribe without active session",
|
|
|
|
session: nil,
|
|
|
|
topic: topics,
|
2023-08-22 21:01:47 +03:00
|
|
|
err: errors.Wrap(mqtt.ErrFailedUnsubscribe, mqtt.ErrClientNotInitialized),
|
2022-11-21 14:40:19 +01:00
|
|
|
},
|
|
|
|
{
|
2023-05-31 13:30:28 +03:00
|
|
|
desc: "unsubscribe with valid session and topics",
|
|
|
|
session: &sessionClient,
|
|
|
|
topic: topics,
|
|
|
|
logMsg: fmt.Sprintf(mqtt.LogInfoUnsubscribed, clientID, topics[0]),
|
2022-11-21 14:40:19 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range cases {
|
2023-05-31 13:30:28 +03:00
|
|
|
ctx := context.TODO()
|
|
|
|
if tc.session != nil {
|
|
|
|
ctx = session.NewContext(ctx, tc.session)
|
|
|
|
}
|
2023-08-22 21:01:47 +03:00
|
|
|
err := handler.Unsubscribe(ctx, &tc.topic)
|
2022-11-21 14:40:19 +01:00
|
|
|
assert.Contains(t, logBuffer.String(), tc.logMsg)
|
2023-08-22 21:01:47 +03:00
|
|
|
assert.Equal(t, tc.err, err)
|
2022-11-21 14:40:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDisconnect(t *testing.T) {
|
|
|
|
handler := newHandler()
|
|
|
|
logBuffer.Reset()
|
|
|
|
|
|
|
|
cases := []struct {
|
2023-05-31 13:30:28 +03:00
|
|
|
desc string
|
|
|
|
session *session.Session
|
|
|
|
topic []string
|
|
|
|
logMsg string
|
2023-08-22 21:01:47 +03:00
|
|
|
err error
|
2022-11-21 14:40:19 +01:00
|
|
|
}{
|
|
|
|
{
|
2023-05-31 13:30:28 +03:00
|
|
|
desc: "disconnect without active session",
|
|
|
|
session: nil,
|
|
|
|
topic: topics,
|
2023-08-22 21:01:47 +03:00
|
|
|
err: errors.Wrap(mqtt.ErrFailedDisconnect, mqtt.ErrClientNotInitialized),
|
2022-11-21 14:40:19 +01:00
|
|
|
},
|
|
|
|
{
|
2023-05-31 13:30:28 +03:00
|
|
|
desc: "disconnect with valid session",
|
|
|
|
session: &sessionClient,
|
|
|
|
topic: topics,
|
2023-08-22 21:01:47 +03:00
|
|
|
err: nil,
|
2022-11-21 14:40:19 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range cases {
|
2023-05-31 13:30:28 +03:00
|
|
|
ctx := context.TODO()
|
|
|
|
if tc.session != nil {
|
|
|
|
ctx = session.NewContext(ctx, tc.session)
|
|
|
|
}
|
2023-08-22 21:01:47 +03:00
|
|
|
err := handler.Disconnect(ctx)
|
2022-11-21 14:40:19 +01:00
|
|
|
assert.Contains(t, logBuffer.String(), tc.logMsg)
|
2023-08-22 21:01:47 +03:00
|
|
|
assert.Equal(t, tc.err, err)
|
2022-11-21 14:40:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func newHandler() session.Handler {
|
|
|
|
logger, err := logger.New(&logBuffer, "debug")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("failed to create logger: %s", err)
|
|
|
|
}
|
NOISSUE - Switch to Google Zanzibar Access control approach (#1919)
* Return Auth service
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Update Compose to run with SpiceDB and Auth svc
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Update auth gRPC API
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Remove Users' policies
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Move Groups to internal
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Use shared groups in Users
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Remove unused code
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Use pkg Groups in Things
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Remove Things groups
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Make imports consistent
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Update Groups networking
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Remove things groups-specific API
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Move Things Clients to the root
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Move Clients to Users root
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Temporarily remove tracing
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Fix imports
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Add buffer config for gRPC
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Update auth type for Things
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Use Auth for login
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Add temporary solution for refresh token
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Update Tokenizer interface
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Updade tokens issuing
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Fix token issuing
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Update JWT validator and refactor Tokenizer
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Rename access timeout
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Rename login to authenticate
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Update Identify to use SubjectID
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Add Auth to Groups
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Use the Auth service for Groups
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Update auth schema
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Fix Auth for Groups
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Add auth for addons (#14)
Signed-off-by: Arvindh <arvindh91@gmail.com>
Speparate Login and Refresh tokens
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Merge authN and authZ requests for things
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Add connect and disconnect
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Update sharing
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Fix policies addition and removal
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Update relation with roels
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Add gRPC to Things
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Assign and Unassign members to group and Listing of Group members (#15)
* add auth for addons
Signed-off-by: Arvindh <arvindh91@gmail.com>
* add assign and unassign to group
Signed-off-by: Arvindh <arvindh91@gmail.com>
* add group incomplete repo implementation
Signed-off-by: Arvindh <arvindh91@gmail.com>
* groups for users
Signed-off-by: Arvindh <arvindh91@gmail.com>
* groups for users
Signed-off-by: Arvindh <arvindh91@gmail.com>
* groups for users
Signed-off-by: Arvindh <arvindh91@gmail.com>
* groups for users
Signed-off-by: Arvindh <arvindh91@gmail.com>
---------
Signed-off-by: Arvindh <arvindh91@gmail.com>
Move coap mqtt and ws policies to spicedb (#16)
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
Remove old policies
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
NOISSUE - Things authorize to return thingID (#18)
This commit modifies the authorize endpoint to the grpc endpoint to return thingID. The authorize endpoint allows adapters to get the publisher of the message.
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
Add Groups to users service (#17)
* add assign and unassign to group
Signed-off-by: Arvindh <arvindh91@gmail.com>
* add group incomplete repo implementation
Signed-off-by: Arvindh <arvindh91@gmail.com>
* groups for users
Signed-off-by: Arvindh <arvindh91@gmail.com>
* groups for users
Signed-off-by: Arvindh <arvindh91@gmail.com>
* groups for users
Signed-off-by: Arvindh <arvindh91@gmail.com>
* groups for users
Signed-off-by: Arvindh <arvindh91@gmail.com>
* groups for users stable 1
Signed-off-by: Arvindh <arvindh91@gmail.com>
* groups for users stable 2
Signed-off-by: Arvindh <arvindh91@gmail.com>
* groups for users & things
Signed-off-by: Arvindh <arvindh91@gmail.com>
* Amend signature
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix merge error
Signed-off-by: Arvindh <arvindh91@gmail.com>
---------
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
* NOISSUE - Fix es code (#21)
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
* NOISSUE - Fix Bugs (#20)
* fix bugs
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix bugs
Signed-off-by: Arvindh <arvindh91@gmail.com>
---------
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
* NOISSUE - Test e2e (#19)
* fix: connect method
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
* fix: e2e
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
* fix changes in sdk and e2e
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
* feat(docker): remove unnecessary port mapping
Remove the port mapping for MQTT broker in the docker-compose.yml file.
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
* Enable group listing
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
* feat(responses): update ChannelsPage struct
The ChannelsPage struct in the responses.go file has been updated. The "Channels" field has been renamed to "Groups" to provide more accurate naming. This change ensures consistency and clarity in the codebase.
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
* feat(things): add UpdateClientSecret method
Add the UpdateClientSecret method to the things service. This method allows updating the client secret for a specific client identified by the provided token, id, and key parameters.
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
---------
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
* Use smaller buffers for gRPC
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
* Clean up tests (#22)
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
* Add Connect Disconnect endpoints (#23)
* fix bugs
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix bugs
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix list of things in a channel and Add connect disconnect endpoint
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix list of things in a channel and Add connect disconnect endpoint
Signed-off-by: Arvindh <arvindh91@gmail.com>
---------
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
* Add: Things share with users (#25)
* fix list of things in a channel and Add connect disconnect endpoint
Signed-off-by: Arvindh <arvindh91@gmail.com>
* add: things share with other users
Signed-off-by: Arvindh <arvindh91@gmail.com>
---------
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
* NOISSUE - Rename gRPC Services (#24)
* Rename things and users auth service
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
* docs: add authorization docs for gRPC services
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
* Rename things and users grpc services
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
* Remove mainflux.env package
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
---------
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
* Add: Listing of things, channels, groups, users (#26)
* add: listing of channels, users, groups, things
Signed-off-by: Arvindh <arvindh91@gmail.com>
* add: listing of channels, users, groups, things
Signed-off-by: Arvindh <arvindh91@gmail.com>
* add: listing of channels, users, groups, things
Signed-off-by: Arvindh <arvindh91@gmail.com>
* add: listing of channels, users, groups, things
Signed-off-by: Arvindh <arvindh91@gmail.com>
---------
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
* NOISSUE - Clean Up Users (#27)
* feat(groups): rename redis package to events
- Renamed the `redis` package to `events` in the `internal/groups` directory.
- Updated the file paths and names accordingly.
- This change reflects the more accurate purpose of the package and improves code organization.
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
* feat(auth): Modify identity method
Change request and response of identity method
Add accessToken and refreshToken to Token response
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
* clean up users, remove dead code
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
* feat(users): add unit tests for user service
This commit adds unit tests for the user service in the `users` package. The tests cover various scenarios and ensure the correct behavior of the service.
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
---------
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
* Add: List of user groups & removed repeating code in groups (#29)
* removed repeating code in list groups
Signed-off-by: Arvindh <arvindh91@gmail.com>
* add: list of user group
Signed-off-by: Arvindh <arvindh91@gmail.com>
* fix: otel handler operator name for endpoints
Signed-off-by: Arvindh <arvindh91@gmail.com>
---------
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
* NOISSUE - Clean Up Things Service (#28)
* Rework things service
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
* add tests
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
---------
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
* NOISSUE - Clean Up Auth Service (#30)
* clean up auth service
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
* feat(auth): remove unused import
Remove the unused import of `emptypb` in `auth.pb.go`. This import is not being used in the codebase and can be safely removed.
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
---------
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
* NOISSUE - Update API docs (#31)
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
* Remove TODO comments and cleanup the code
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
* Update dependenices
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
---------
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
Co-authored-by: b1ackd0t <28790446+rodneyosodo@users.noreply.github.com>
Co-authored-by: Arvindh <30824765+arvindh123@users.noreply.github.com>
2023-10-15 22:02:13 +02:00
|
|
|
auth := new(authmocks.Service)
|
2022-11-21 14:40:19 +01:00
|
|
|
eventStore := mocks.NewEventStore()
|
NOISSUE - Make MQTT Broker Configurable (#1904)
* Minor changes on mqtt publisher using nats
Signed-off-by: Rodney Osodo <socials@rodneyosodo.com>
* Remove vernemq dependencies
Signed-off-by: Rodney Osodo <socials@rodneyosodo.com>
* Restore VerneMQ config files
Signed-off-by: Rodney Osodo <socials@rodneyosodo.com>
* Fix Makefile to support custom Docker profiles
The Makefile has been updated to support custom Docker profiles.
Previously, the Makefile only supported the default profiles for the
message broker and MQTT broker. Now, the Makefile allows for custom
profiles to be specified using environment variables. If the
MF_BROKER_TYPE or MF_MQTT_BROKER_TYPE variables are not set, the
default values "nats" and "nats" will be used, respectively. This
change enables more flexibility in configuring the Docker environment
for the project.
The `run` target has also been modified to use the correct broker
configuration file based on the MF_BROKER_TYPE variable. The sed
command in the `run` target now replaces the placeholder in the
docker/docker-compose.yml file with the appropriate broker
configuration file.
This commit improves the Makefile to support custom Docker profiles
and ensures the correct broker configuration file is used when
running the project.
Signed-off-by: Rodney Osodo <socials@rodneyosodo.com>
* Fix queue binding issue in RabbitMQ pubsub
The commit fixes an issue in the RabbitMQ pubsub implementation where the queue binding was not correctly set up. Instead of using the topic as the queue name, the commit now uses a unique client ID generated by combining the topic and subscriber ID. This ensures that each subscriber has its own dedicated queue. The commit also updates the queue binding to use the correct queue name.
Signed-off-by: Rodney Osodo <socials@rodneyosodo.com>
* Refactor Docker config editing in Makefile
The commit refactors the `edit_docker_config` function in the Makefile to improve readability and maintainability. The changes include:
- Removing unnecessary conditionals related to the `rabbitmq` broker
These changes ensure that the Docker configuration is correctly updated based on the specified MQTT broker type.
Signed-off-by: Rodney Osodo <socials@rodneyosodo.com>
* Fix failing tests on RabbitMQ
Signed-off-by: Rodney Osodo <socials@rodneyosodo.com>
* Refactor MQTT_BROKER comment in docker-compose.yml
The MQTT_BROKER comment in the docker-compose.yml file has been updated to provide a more accurate description of its functionality. The comment now states that the MQTT_BROKER handles MQTT communication between MQTT adapters and the message broker, instead of Mainflux services. This change improves clarity and aligns with the actual purpose of the MQTT_BROKER.
Signed-off-by: Rodney Osodo <socials@rodneyosodo.com>
* Rename `MF_BROKER` to `MF_MESSAGE_BROKER`
The Makefile and Semaphore configuration files have been refactored to update the variable names related to the message broker type.
These changes ensure consistency and clarity in the codebase by using more descriptive variable names related to the message broker type.
Signed-off-by: Rodney Osodo <socials@rodneyosodo.com>
* Fix Docker profile configuration for nats_rabbitmq
Update the Docker profile configuration for nats_rabbitmq by replacing the NATS URL in the .env file with the correct value.
Signed-off-by: Rodney Osodo <socials@rodneyosodo.com>
* Rename MF_BROKER_URL to MF_MESSAGE_BROKER_URL
Signed-off-by: Rodney Osodo <socials@rodneyosodo.com>
* Fix MQTT QoS level in pubsub.go
The MQTT QoS level in the pubsub.go file was set to 1, which is the
default level. However, since NATS supports up to QoS 1, I updated the
QoS level comment to reflect this.
Signed-off-by: Rodney Osodo <socials@rodneyosodo.com>
* Refactor NewPublisher to accept QoS parameter
The NewPublisher function in the pkg/messaging/mqtt/publisher.go file has been refactored to accept a new parameter, qos, which represents the Quality of Service level for MQTT message publishing. This change allows for more flexibility in configuring the MQTT publisher.
The NewPublisher function now has the following signature:
```go
func NewPublisher(address string, qos uint8, timeout time.Duration) (messaging.Publisher, error)
```
This change ensures that the MQTT publisher can be created with the desired QoS level, enhancing the reliability and delivery guarantees of the published messages.
Signed-off-by: Rodney Osodo <socials@rodneyosodo.com>
* Fix test assertions in pubsub_test.go
The test assertions in the pubsub_test.go file were incorrect. This commit fixes the assertions to properly compare the expected and received message values.
Signed-off-by: Rodney Osodo <socials@rodneyosodo.com>
* Test configurable MQTT broker
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
---------
Signed-off-by: Rodney Osodo <socials@rodneyosodo.com>
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
2023-10-19 22:01:09 +03:00
|
|
|
return mqtt.NewHandler(mocks.NewPublisher(), eventStore, logger, auth)
|
2022-11-21 14:40:19 +01:00
|
|
|
}
|