forked from gptscript-ai/gptscript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcred_test.go
47 lines (39 loc) · 1.56 KB
/
cred_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package integration
import (
"strings"
"testing"
"time"
"github.com/stretchr/testify/require"
)
func TestGPTScriptCredential(t *testing.T) {
out, err := GPTScriptExec("cred")
require.NoError(t, err)
require.Contains(t, out, "CREDENTIAL")
}
// TestCredentialScopes makes sure that environment variables set by credential tools and shared credential tools
// are only available to the correct tools. See scripts/credscopes.gpt for more details.
func TestCredentialScopes(t *testing.T) {
out, err := RunScript("scripts/cred_scopes.gpt", "--sub-tool", "oneOne")
require.NoError(t, err)
require.Contains(t, out, "good")
out, err = RunScript("scripts/cred_scopes.gpt", "--sub-tool", "twoOne")
require.NoError(t, err)
require.Contains(t, out, "good")
out, err = RunScript("scripts/cred_scopes.gpt", "--sub-tool", "twoTwo")
require.NoError(t, err)
require.Contains(t, out, "good")
}
// TestCredentialExpirationEnv tests a GPTScript with two credentials that expire at different times.
// One expires after two hours, and the other expires after one hour.
// This test makes sure that the GPTSCRIPT_CREDENTIAL_EXPIRATION environment variable is set to the nearer expiration time (1h).
func TestCredentialExpirationEnv(t *testing.T) {
out, err := RunScript("scripts/cred_expiration.gpt")
require.NoError(t, err)
for _, line := range strings.Split(out, "\n") {
if timestamp, found := strings.CutPrefix(line, "Expires: "); found {
expiresTime, err := time.Parse(time.RFC3339, timestamp)
require.NoError(t, err)
require.True(t, time.Until(expiresTime) < time.Hour)
}
}
}