1
1
package integration
2
2
3
3
import (
4
+ "strings"
4
5
"testing"
6
+ "time"
5
7
6
8
"github.com/stretchr/testify/require"
7
9
)
@@ -15,15 +17,31 @@ func TestGPTScriptCredential(t *testing.T) {
15
17
// TestCredentialScopes makes sure that environment variables set by credential tools and shared credential tools
16
18
// are only available to the correct tools. See scripts/credscopes.gpt for more details.
17
19
func 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" )
19
21
require .NoError (t , err )
20
22
require .Contains (t , out , "good" )
21
23
22
- out , err = RunScript ("scripts/credscopes .gpt" , "--sub-tool" , "twoOne" )
24
+ out , err = RunScript ("scripts/cred_scopes .gpt" , "--sub-tool" , "twoOne" )
23
25
require .NoError (t , err )
24
26
require .Contains (t , out , "good" )
25
27
26
- out , err = RunScript ("scripts/credscopes .gpt" , "--sub-tool" , "twoTwo" )
28
+ out , err = RunScript ("scripts/cred_scopes .gpt" , "--sub-tool" , "twoTwo" )
27
29
require .NoError (t , err )
28
30
require .Contains (t , out , "good" )
29
31
}
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