bf9395e022
CI / license-header (push) Has been skipped
CI / e2e-dry-run (push) Has been skipped
CI / fast-gate (push) Failing after 0s
Test PR Label Logic / test-pr-labels (push) Failing after 1s
Skill Format Check / check-format (push) Failing after 2s
CI / security (push) Failing after 5s
CI / unit-test (push) Has been skipped
CI / lint (push) Has been skipped
CI / script-test (push) Has been skipped
CI / deterministic-gate (push) Has been skipped
CI / coverage (push) Has been skipped
CI / results (push) Has been cancelled
CI / deadcode (push) Has been cancelled
CI / e2e-live (push) Has been cancelled
82 lines
1.9 KiB
Go
82 lines
1.9 KiB
Go
// Copyright (c) 2026 Lark Technologies Pte. Ltd.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package auth
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
extcred "github.com/larksuite/cli/extension/credential"
|
|
"github.com/larksuite/cli/internal/cmdutil"
|
|
"github.com/larksuite/cli/internal/core"
|
|
)
|
|
|
|
func TestAuthLogin_StrictModeBot_Blocked(t *testing.T) {
|
|
cfg := &core.CliConfig{
|
|
AppID: "a", AppSecret: "s",
|
|
SupportedIdentities: uint8(extcred.SupportsBot),
|
|
}
|
|
f, _, _, _ := cmdutil.TestFactory(t, cfg)
|
|
|
|
var called bool
|
|
cmd := NewCmdAuthLogin(f, func(opts *LoginOptions) error {
|
|
called = true
|
|
return nil
|
|
})
|
|
cmd.SetArgs([]string{"--scope", "contact:user.base:readonly"})
|
|
|
|
err := cmd.Execute()
|
|
if called {
|
|
t.Error("runF should not be called in bot strict mode")
|
|
}
|
|
if err == nil {
|
|
t.Fatal("expected error in bot strict mode")
|
|
}
|
|
if !strings.Contains(err.Error(), "strict mode") {
|
|
t.Errorf("error should mention strict mode, got: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestAuthLogin_StrictModeUser_Allowed(t *testing.T) {
|
|
cfg := &core.CliConfig{
|
|
AppID: "a", AppSecret: "s",
|
|
SupportedIdentities: uint8(extcred.SupportsUser),
|
|
}
|
|
f, _, _, _ := cmdutil.TestFactory(t, cfg)
|
|
|
|
var called bool
|
|
cmd := NewCmdAuthLogin(f, func(opts *LoginOptions) error {
|
|
called = true
|
|
return nil
|
|
})
|
|
cmd.SetArgs([]string{"--scope", "contact:user.base:readonly"})
|
|
|
|
err := cmd.Execute()
|
|
if !called {
|
|
t.Error("runF should be called in user strict mode")
|
|
}
|
|
if err != nil {
|
|
t.Errorf("unexpected error: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestAuthLogin_StrictModeOff_Allowed(t *testing.T) {
|
|
f, _, _, _ := cmdutil.TestFactory(t, &core.CliConfig{AppID: "a", AppSecret: "s"})
|
|
|
|
var called bool
|
|
cmd := NewCmdAuthLogin(f, func(opts *LoginOptions) error {
|
|
called = true
|
|
return nil
|
|
})
|
|
cmd.SetArgs([]string{"--scope", "contact:user.base:readonly"})
|
|
|
|
err := cmd.Execute()
|
|
if !called {
|
|
t.Error("runF should be called when strict mode is off")
|
|
}
|
|
if err != nil {
|
|
t.Errorf("unexpected error: %v", err)
|
|
}
|
|
}
|