Skip to content

Commit

Permalink
removed private link, replaced by keygen
Browse files Browse the repository at this point in the history
  • Loading branch information
kelindar committed Oct 19, 2019
1 parent 438c018 commit 5e26d2b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
11 changes: 1 addition & 10 deletions internal/broker/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,17 +249,8 @@ func (c *Conn) onLink(payload []byte) (response, bool) {
return errors.ErrLinkInvalid, false
}

// Make the channel from the request or try to make a private one
channel := security.MakeChannel(request.Key, request.Channel)
if request.Private {
priv, err := c.keys.ExtendKey(request.Key, request.Channel, c.ID(), security.AllowAll, time.Unix(0, 0))
if err != nil {
return err, false
}
channel = priv
}

// Ensures that the channel requested is valid
channel := security.MakeChannel(request.Key, request.Channel)
if channel == nil || channel.ChannelType == security.ChannelInvalid {
return errors.ErrBadRequest, false
}
Expand Down
1 change: 0 additions & 1 deletion internal/broker/handlers_dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ type linkRequest struct {
Key string `json:"key"` // The key for the channel.
Channel string `json:"channel"` // The channel name for the shortcut.
Subscribe bool `json:"subscribe"` // Specifies whether the broker should auto-subscribe.
Private bool `json:"private"` // Specifies whether the broker should generate a private link.
}

// ------------------------------------------------------------------------------------
Expand Down
16 changes: 10 additions & 6 deletions internal/broker/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestHandlers_onLink(t *testing.T) {
success bool
}{
{
packet: `{ "name": "AB", "key": "k44Ss59ZSxg6Zyz39kLwN-2t5AETnGpm", "channel": "a/b/c/", "private": true, "subscribe": true }`,
packet: `{ "name": "AB", "key": "k44Ss59ZSxg6Zyz39kLwN-2t5AETnGpm", "channel": "a/b/c/", "subscribe": true }`,
channel: "a/b/c/",
success: true,
},
Expand All @@ -49,11 +49,15 @@ func TestHandlers_onLink(t *testing.T) {
channel: "a/b/c/",
success: true,
},
{packet: `{ "name": "ABC", "key": "k44Ss59ZSxg6Zyz39kLwN-2t5AETnGpm", "channel": "a/b/c/", "private": true, "subscribe": true }`},
{packet: `{ "name": "", "key": "k44Ss59ZSxg6Zyz39kLwN-2t5AETnGpm", "channel": "a/b/c/", "private": true, "subscribe": true }`},
{packet: `{"key": "k44Ss59ZSxg6Zyz39kLwN-2t5AETnGpm", "channel": "a/b/c/", "private": true, "subscribe": true }`},
{packet: `{ "name": "AB", "key": "k44Ss59ZSxg6Zyz39kLwN-2t5AETnGpm", "channel": "---", "private": true, "subscribe": true }`},
{packet: `{ "name": "AB", "key": "xxx", "channel": "a/b/c/", "private": true, "subscribe": true }`},
{
packet: `{ "name": "AB", "key": "xxx", "channel": "a/b/c/", "subscribe": true }`,
channel: "a/b/c/",
success: true,
},
{packet: `{ "name": "ABC", "key": "k44Ss59ZSxg6Zyz39kLwN-2t5AETnGpm", "channel": "a/b/c/", "subscribe": true }`},
{packet: `{ "name": "", "key": "k44Ss59ZSxg6Zyz39kLwN-2t5AETnGpm", "channel": "a/b/c/", "subscribe": true }`},
{packet: `{"key": "k44Ss59ZSxg6Zyz39kLwN-2t5AETnGpm", "channel": "a/b/c/", "subscribe": true }`},
{packet: `{ "name": "AB", "key": "k44Ss59ZSxg6Zyz39kLwN-2t5AETnGpm", "channel": "---", "subscribe": true }`},
}

for _, tc := range tests {
Expand Down

0 comments on commit 5e26d2b

Please sign in to comment.