-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor client API to return whole app * monitor for expected permissions * MM-59549: monitor permissions To aid in debugging deployments, let's periodically check the application permissions and log those missing or redundant. Fixes: https://mattermost.atlassian.net/browse/MM-59549
- Loading branch information
1 parent
838e99d
commit 3908fde
Showing
8 changed files
with
275 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/mattermost/mattermost-plugin-msteams/server/msteams/clientmodels" | ||
"github.com/mattermost/mattermost/server/public/model" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestDescribeResourceAccessType(t *testing.T) { | ||
assert.Equal(t, "Scope (Delegated)", describeResourceAccessType(clientmodels.ResourceAccess{ | ||
ID: model.NewId(), | ||
Type: ResourceAccessTypeScope, | ||
})) | ||
assert.Equal(t, "Role (Application)", describeResourceAccessType(clientmodels.ResourceAccess{ | ||
ID: model.NewId(), | ||
Type: ResourceAccessTypeRole, | ||
})) | ||
assert.Equal(t, "Unknown", describeResourceAccessType(clientmodels.ResourceAccess{ | ||
ID: model.NewId(), | ||
Type: "Unknown", | ||
})) | ||
} | ||
|
||
func TestCheckPermissions(t *testing.T) { | ||
th := setupTestHelper(t) | ||
|
||
t.Run("no permissions", func(t *testing.T) { | ||
th.Reset(t) | ||
|
||
var app clientmodels.App | ||
|
||
missing, redundant := th.p.checkPermissions(&app) | ||
|
||
assert.Equal(t, getExpectedPermissions(), missing) | ||
assert.Empty(t, redundant) | ||
}) | ||
|
||
t.Run("missing and redundant permissions", func(t *testing.T) { | ||
th.Reset(t) | ||
|
||
var app clientmodels.App | ||
|
||
var changedResourceAccess clientmodels.ResourceAccess | ||
for i, expectedPermission := range getExpectedPermissions() { | ||
if i == 0 { | ||
// Skip the first permission altogether | ||
continue | ||
} else if i == 1 { | ||
// Change the type of the second permission | ||
changedResourceAccess = expectedPermission.ResourceAccess | ||
if changedResourceAccess.Type == ResourceAccessTypeScope { | ||
changedResourceAccess.Type = ResourceAccessTypeRole | ||
} else { | ||
changedResourceAccess.Type = ResourceAccessTypeScope | ||
} | ||
app.RequiredResources = append(app.RequiredResources, changedResourceAccess) | ||
} else { | ||
app.RequiredResources = append(app.RequiredResources, expectedPermission.ResourceAccess) | ||
} | ||
} | ||
|
||
// Add an extra permission beyond the changed one above. | ||
extraResourceAccess := clientmodels.ResourceAccess{ | ||
ID: model.NewId(), | ||
Type: ResourceAccessTypeRole, | ||
} | ||
app.RequiredResources = append(app.RequiredResources, extraResourceAccess) | ||
|
||
missing, redundant := th.p.checkPermissions(&app) | ||
assert.Equal(t, []expectedPermission{ | ||
getExpectedPermissions()[0], | ||
getExpectedPermissions()[1], | ||
}, missing) | ||
assert.Equal(t, []clientmodels.ResourceAccess{ | ||
changedResourceAccess, | ||
extraResourceAccess, | ||
}, redundant) | ||
}) | ||
|
||
t.Run("expected permissions", func(t *testing.T) { | ||
th.Reset(t) | ||
|
||
var app clientmodels.App | ||
|
||
for _, expectedPermission := range getExpectedPermissions() { | ||
app.RequiredResources = append(app.RequiredResources, expectedPermission.ResourceAccess) | ||
} | ||
|
||
missing, redundant := th.p.checkPermissions(&app) | ||
assert.Empty(t, missing) | ||
assert.Empty(t, redundant) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
server/msteams/client_disconnectionlayer/disconnectionlayer.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.