[MM-29845] Add a new handler to allow authentication via CWS API Key (#16319)
* Add a new handler to allow authentication via CWS API Key * Make error better * Add tests and cases for new handler functions * Move some code around * Add test for GetCloudSession function * unset the env after test completion * Remove white space * Change Info to Warn Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
@@ -5,6 +5,7 @@ package app
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -404,3 +405,35 @@ func TestApp_SetSessionExpireInDays(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetCloudSession(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer func() {
|
||||
os.Unsetenv("MM_CLOUD_API_KEY")
|
||||
th.TearDown()
|
||||
}()
|
||||
|
||||
t.Run("Matching environment variable and token should return non-nil session", func(t *testing.T) {
|
||||
os.Setenv("MM_CLOUD_API_KEY", "mytoken")
|
||||
session, err := th.App.GetCloudSession("mytoken")
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, session)
|
||||
require.Equal(t, "mytoken", session.Token)
|
||||
})
|
||||
|
||||
t.Run("Empty environment variable should return error", func(t *testing.T) {
|
||||
os.Setenv("MM_CLOUD_API_KEY", "")
|
||||
session, err := th.App.GetCloudSession("mytoken")
|
||||
require.Nil(t, session)
|
||||
require.NotNil(t, err)
|
||||
require.Equal(t, "api.context.invalid_token.error", err.Id)
|
||||
})
|
||||
|
||||
t.Run("Mismatched env variable and token should return error", func(t *testing.T) {
|
||||
os.Setenv("MM_CLOUD_API_KEY", "mytoken")
|
||||
session, err := th.App.GetCloudSession("myincorrecttoken")
|
||||
require.Nil(t, session)
|
||||
require.NotNil(t, err)
|
||||
require.Equal(t, "api.context.invalid_token.error", err.Id)
|
||||
})
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user