@@ -88,7 +88,8 @@ async fn login_with_agent_identity_writes_only_token() {
8888 let dir = tempdir ( ) . unwrap ( ) ;
8989 let auth_path = dir. path ( ) . join ( "auth.json" ) ;
9090 let record = agent_identity_record ( "account-123" ) ;
91- let agent_identity = signed_agent_identity_jwt ( & record) . expect ( "signed agent identity" ) ;
91+ let agent_identity =
92+ signed_agent_identity_jwt ( & record, json ! ( record. plan_type) ) . expect ( "signed agent identity" ) ;
9293 let server = MockServer :: start ( ) . await ;
9394 Mock :: given ( method ( "GET" ) )
9495 . and ( path ( "/backend-api/wham/agent-identities/jwks" ) )
@@ -709,7 +710,8 @@ async fn load_auth_reads_agent_identity_from_env() {
709710 let codex_home = tempdir ( ) . unwrap ( ) ;
710711 let expected_record = agent_identity_record ( "account-123" ) ;
711712 let agent_identity =
712- signed_agent_identity_jwt ( & expected_record) . expect ( "signed agent identity" ) ;
713+ signed_agent_identity_jwt ( & expected_record, json ! ( expected_record. plan_type) )
714+ . expect ( "signed agent identity" ) ;
713715 let server = MockServer :: start ( ) . await ;
714716 Mock :: given ( method ( "GET" ) )
715717 . and ( path ( "/backend-api/wham/agent-identities/jwks" ) )
@@ -925,6 +927,13 @@ fn agent_identity_record(account_id: &str) -> AgentIdentityAuthRecord {
925927}
926928
927929fn fake_agent_identity_jwt ( record : & AgentIdentityAuthRecord ) -> std:: io:: Result < String > {
930+ fake_agent_identity_jwt_with_plan_type ( record, serde_json:: to_value ( record. plan_type ) ?)
931+ }
932+
933+ fn fake_agent_identity_jwt_with_plan_type (
934+ record : & AgentIdentityAuthRecord ,
935+ plan_type : serde_json:: Value ,
936+ ) -> std:: io:: Result < String > {
928937 let encode = |bytes : & [ u8 ] | base64:: engine:: general_purpose:: URL_SAFE_NO_PAD . encode ( bytes) ;
929938 let header_b64 = encode ( br#"{"alg":"EdDSA","typ":"JWT"}"# ) ;
930939 let payload = json ! ( {
@@ -937,7 +946,7 @@ fn fake_agent_identity_jwt(record: &AgentIdentityAuthRecord) -> std::io::Result<
937946 "account_id" : record. account_id,
938947 "chatgpt_user_id" : record. chatgpt_user_id,
939948 "email" : record. email,
940- "plan_type" : record . plan_type,
949+ "plan_type" : plan_type,
941950 "chatgpt_account_is_fedramp" : record. chatgpt_account_is_fedramp,
942951 } ) ;
943952 let payload_b64 = encode ( & serde_json:: to_vec ( & payload) ?) ;
@@ -947,6 +956,7 @@ fn fake_agent_identity_jwt(record: &AgentIdentityAuthRecord) -> std::io::Result<
947956
948957fn signed_agent_identity_jwt (
949958 record : & AgentIdentityAuthRecord ,
959+ plan_type : serde_json:: Value ,
950960) -> jsonwebtoken:: errors:: Result < String > {
951961 let mut header = jsonwebtoken:: Header :: new ( jsonwebtoken:: Algorithm :: RS256 ) ;
952962 header. kid = Some ( "test-key" . to_string ( ) ) ;
@@ -962,7 +972,7 @@ fn signed_agent_identity_jwt(
962972 "account_id" : record. account_id,
963973 "chatgpt_user_id" : record. chatgpt_user_id,
964974 "email" : record. email,
965- "plan_type" : record . plan_type,
975+ "plan_type" : plan_type,
966976 "chatgpt_account_is_fedramp" : record. chatgpt_account_is_fedramp,
967977 } ) ,
968978 & jsonwebtoken:: EncodingKey :: from_rsa_pem ( TEST_AGENT_IDENTITY_RSA_PRIVATE_KEY_PEM ) ?,
@@ -1011,6 +1021,48 @@ J1bwkqKZTB5dHolX9A58e/xXnfZ5P8f3Z83+Izap3FwqQulk7b1WO1MQcHuVg2NN
101110218U4M2TSWCKUY/A6sT4W8+mT9
10121022-----END PRIVATE KEY-----"# ;
10131023
1024+ #[ tokio:: test]
1025+ #[ serial( codex_auth_env) ]
1026+ async fn agent_identity_plan_type_maps_raw_enterprise_alias ( ) {
1027+ assert_agent_identity_plan_alias ( json ! ( "hc" ) , AccountPlanType :: Enterprise ) . await ;
1028+ }
1029+
1030+ #[ tokio:: test]
1031+ #[ serial( codex_auth_env) ]
1032+ async fn agent_identity_plan_type_maps_raw_education_alias ( ) {
1033+ assert_agent_identity_plan_alias ( json ! ( "education" ) , AccountPlanType :: Edu ) . await ;
1034+ }
1035+
1036+ async fn assert_agent_identity_plan_alias (
1037+ plan_type : serde_json:: Value ,
1038+ expected_plan_type : AccountPlanType ,
1039+ ) {
1040+ let record = agent_identity_record ( "account-id" ) ;
1041+ let jwt = signed_agent_identity_jwt ( & record, plan_type) . expect ( "agent identity jwt" ) ;
1042+ let server = MockServer :: start ( ) . await ;
1043+ Mock :: given ( method ( "GET" ) )
1044+ . and ( path ( "/backend-api/wham/agent-identities/jwks" ) )
1045+ . respond_with ( ResponseTemplate :: new ( 200 ) . set_body_json ( test_jwks_body ( ) ) )
1046+ . expect ( 1 )
1047+ . mount ( & server)
1048+ . await ;
1049+ Mock :: given ( method ( "POST" ) )
1050+ . and ( path ( "/backend-api/v1/agent/agent-runtime-id/task/register" ) )
1051+ . respond_with ( ResponseTemplate :: new ( 200 ) . set_body_json ( json ! ( {
1052+ "task_id" : "task-123" ,
1053+ } ) ) )
1054+ . expect ( 1 )
1055+ . mount ( & server)
1056+ . await ;
1057+ let chatgpt_base_url = format ! ( "{}/backend-api" , server. uri( ) ) ;
1058+ let auth = CodexAuth :: from_agent_identity_jwt ( & jwt, Some ( & chatgpt_base_url) )
1059+ . await
1060+ . expect ( "agent identity auth" ) ;
1061+
1062+ pretty_assertions:: assert_eq!( auth. account_plan_type( ) , Some ( expected_plan_type) ) ;
1063+ server. verify ( ) . await ;
1064+ }
1065+
10141066#[ tokio:: test]
10151067#[ serial( codex_auth_env) ]
10161068async fn plan_type_maps_known_plan ( ) {
0 commit comments