11package integration
22
33import (
4+ "strings"
45 "testing"
6+ "time"
57
68 "github.com/stretchr/testify/require"
79)
@@ -15,15 +17,31 @@ func TestGPTScriptCredential(t *testing.T) {
1517// TestCredentialScopes makes sure that environment variables set by credential tools and shared credential tools
1618// are only available to the correct tools. See scripts/credscopes.gpt for more details.
1719func TestCredentialScopes (t * testing.T ) {
18- out , err := RunScript ("scripts/credscopes .gpt" , "--sub-tool" , "oneOne" )
20+ out , err := RunScript ("scripts/cred_scopes .gpt" , "--sub-tool" , "oneOne" )
1921 require .NoError (t , err )
2022 require .Contains (t , out , "good" )
2123
22- out , err = RunScript ("scripts/credscopes .gpt" , "--sub-tool" , "twoOne" )
24+ out , err = RunScript ("scripts/cred_scopes .gpt" , "--sub-tool" , "twoOne" )
2325 require .NoError (t , err )
2426 require .Contains (t , out , "good" )
2527
26- out , err = RunScript ("scripts/credscopes .gpt" , "--sub-tool" , "twoTwo" )
28+ out , err = RunScript ("scripts/cred_scopes .gpt" , "--sub-tool" , "twoTwo" )
2729 require .NoError (t , err )
2830 require .Contains (t , out , "good" )
2931}
32+
33+ // TestCredentialExpirationEnv tests a GPTScript with two credentials that expire at different times.
34+ // One expires after two hours, and the other expires after one hour.
35+ // This test makes sure that the GPTSCRIPT_CREDENTIAL_EXPIRATION environment variable is set to the nearer expiration time (1h).
36+ func TestCredentialExpirationEnv (t * testing.T ) {
37+ out , err := RunScript ("scripts/cred_expiration.gpt" )
38+ require .NoError (t , err )
39+
40+ for _ , line := range strings .Split (out , "\n " ) {
41+ if timestamp , found := strings .CutPrefix (line , "Expires: " ); found {
42+ expiresTime , err := time .Parse (time .RFC3339 , timestamp )
43+ require .NoError (t , err )
44+ require .True (t , time .Until (expiresTime ) < time .Hour )
45+ }
46+ }
47+ }
0 commit comments