Skip to content

Commit

Permalink
[MI-3598] Handled all the nil pointer dereference possibilities in th…
Browse files Browse the repository at this point in the history
…e client.go file (#336)

* [MI-3598] Handled all the nil pointer dereference possibilities in the client.go file
Modified the client struct to accept a log service instead of log function

* [MI-3598] Added an additional log in MessageHasBeenUpdated hook
  • Loading branch information
manojmalik20 authored Oct 6, 2023
1 parent d7ffdc0 commit 839ca0b
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 84 deletions.
2 changes: 1 addition & 1 deletion server/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ func (a *API) oauthRedirectHandler(w http.ResponseWriter, r *http.Request) {
return
}

client := msteams.NewTokenClient(a.p.GetURL()+"/oauth-redirect", a.p.configuration.TenantID, a.p.configuration.ClientID, a.p.configuration.ClientSecret, token, a.p.API.LogError)
client := msteams.NewTokenClient(a.p.GetURL()+"/oauth-redirect", a.p.configuration.TenantID, a.p.configuration.ClientID, a.p.configuration.ClientSecret, token, &a.p.apiClient.Log)
if err = client.Connect(); err != nil {
a.p.API.LogError("Unable to connect to the client", "error", err.Error())
http.Error(w, "failed to connect to the client", http.StatusInternalServerError)
Expand Down
1 change: 1 addition & 0 deletions server/message_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ func (p *Plugin) MessageHasBeenUpdated(c *plugin.Context, newPost, oldPost *mode
var chat *msteams.Chat
chat, err = client.CreateOrGetChatForUsers(usersIDs)
if err != nil {
p.API.LogError("Unable to create or get chat for users", "error", err.Error())
return
}
err = p.UpdateChat(chat.ID, user, newPost, oldPost, updateRequired)
Expand Down
1 change: 1 addition & 0 deletions server/message_hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ func TestMessageHasBeenUpdated(t *testing.T) {
api.On("GetUser", testutils.GetID()).Return(testutils.GetUser(model.SystemAdminRoleId, "test@test.com"), nil).Times(1)
api.On("GetChannel", testutils.GetChannelID()).Return(testutils.GetChannel(model.ChannelTypeDirect), nil).Times(1)
api.On("GetChannelMembers", testutils.GetChannelID(), 0, math.MaxInt32).Return(testutils.GetChannelMembers(2), nil).Times(1)
api.On("LogError", "Unable to create or get chat for users", "error", "unable to create or get chat for users").Return().Once()
},
SetupStore: func(store *storemocks.Store) {
store.On("GetLinkByChannelID", testutils.GetChannelID()).Return(nil, nil).Times(1)
Expand Down
Loading

0 comments on commit 839ca0b

Please sign in to comment.