server/browser_password_ui_test.go (1306B)
1 package main 2 3 import ( 4 "ao/server/assets" 5 "bytes" 6 "context" 7 "net/http/httptest" 8 "os" 9 "os/exec" 10 "path/filepath" 11 "runtime" 12 "testing" 13 "time" 14 ) 15 16 func TestBrowserPasswordOptions(t *testing.T) { 17 if os.Getenv("AO_GAME_TEST") != "1" { 18 t.Skip("set AO_GAME_TEST=1 for password changes through the Options overlay") 19 } 20 _, source, _, _ := runtime.Caller(0) 21 root := filepath.Dir(filepath.Dir(source)) 22 useResources(t, assets.Files) 23 world := newTestServer(t) 24 world.baseURL = "/share/test/" 25 startTestService(t, world) 26 host := httptest.NewServer(world.httpHandler()) 27 defer host.Close() 28 ctx, cancel := context.WithTimeout(context.Background(), 4*time.Minute) 29 defer cancel() 30 31 command := exec.CommandContext(ctx, "node", filepath.Join(root, "tools/client/test_password_options.mjs"), host.URL+world.baseURL, filepath.Join(root, "local/password-options")) 32 command.Dir, command.Stdout, command.Stderr = root, os.Stdout, os.Stderr 33 if err := command.Run(); err != nil { 34 t.Fatal(err) 35 } 36 37 var salt, hash []byte 38 if err := world.db.QueryRow("SELECT password_salt,password_hash FROM characters WHERE name='Passwordtest'").Scan(&salt, &hash); err != nil { 39 t.Fatal(err) 40 } 41 if !bytes.Equal(hash, world.browserPassword("valid", salt)) { 42 t.Fatal("Options password change did not reach the database") 43 } 44 }