@@ -1227,6 +1227,53 @@ func TestRemoteLoginStoresKeyringToken(t *testing.T) {
12271227 require .Contains (t , whoami .String (), `"login": "alice"` )
12281228}
12291229
1230+ func TestRemoteLoginWithGitHubTokenEnvStoresKeyringToken (t * testing.T ) {
1231+ ctx := context .Background ()
1232+ dir := t .TempDir ()
1233+ keyring .MockInit ()
1234+ t .Setenv ("DISCRAWL_TEST_GITHUB_TOKEN" , "github-token" )
1235+
1236+ var sawToken string
1237+ server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , req * http.Request ) {
1238+ w .Header ().Set ("content-type" , "application/json" )
1239+ switch req .URL .Path {
1240+ case "/v1/auth/github/token" :
1241+ var body crawlremote.GitHubTokenLoginRequest
1242+ require .NoError (t , json .NewDecoder (req .Body ).Decode (& body ))
1243+ sawToken = body .Token
1244+ _ = json .NewEncoder (w ).Encode (crawlremote.LoginPollResult {Status : "complete" , Token : "session-token" , Org : "openclaw" , Login : "alice" })
1245+ case "/v1/whoami" :
1246+ require .Equal (t , "Bearer session-token" , req .Header .Get ("Authorization" ))
1247+ _ = json .NewEncoder (w ).Encode (crawlremote.Identity {Owner : "openclaw" , Org : "openclaw" , Login : "alice" , Auth : "github" })
1248+ default :
1249+ http .NotFound (w , req )
1250+ }
1251+ }))
1252+ defer server .Close ()
1253+
1254+ cfgPath := filepath .Join (dir , "config.toml" )
1255+ var out bytes.Buffer
1256+ require .NoError (t , Run (ctx , []string {
1257+ "--config" , cfgPath ,
1258+ "--json" ,
1259+ "remote" , "login" ,
1260+ "--endpoint" , server .URL ,
1261+ "--github-token-env" , "DISCRAWL_TEST_GITHUB_TOKEN" ,
1262+ }, & out , & bytes.Buffer {}))
1263+ require .Equal (t , "github-token" , sawToken )
1264+ require .Contains (t , out .String (), `"login_method": "github-token"` )
1265+
1266+ cfg , err := config .Load (cfgPath )
1267+ require .NoError (t , err )
1268+ stored , err := keyring .Get (cfg .Remote .Auth .KeyringService , cfg .Remote .Auth .KeyringAccount )
1269+ require .NoError (t , err )
1270+ require .Equal (t , "session-token" , stored )
1271+
1272+ var whoami bytes.Buffer
1273+ require .NoError (t , Run (ctx , []string {"--config" , cfgPath , "--json" , "whoami" }, & whoami , & bytes.Buffer {}))
1274+ require .Contains (t , whoami .String (), `"login": "alice"` )
1275+ }
1276+
12301277func TestCloudPublishSendsNonDMRows (t * testing.T ) {
12311278 ctx := context .Background ()
12321279 dir := t .TempDir ()
0 commit comments