Beispiel #1
0
func newTestServer(t *testing.T) (*httptest.Server, chan bool) {
	done := make(chan bool)
	tmpd, err := ioutil.TempDir("/tmp", "erickson")
	if err != nil {
		t.Fatal(err)
	}
	go func() {
		<-done
		if err := os.RemoveAll(tmpd); err != nil {
			t.Fatal(err)
		}
	}()
	db, err := db.NewBoltDB(tmpd + "/erickson.db")
	if err != nil {
		t.Fatal(err)
	}
	u, err := review.NewUser("bob", "supersecret")
	if err != nil {
		t.Fatal(err)
	}
	if err := db.CreateUser(u); err != nil {
		t.Fatal(err)
	}
	key := []byte("12345678901234567890123456789012")
	return httptest.NewServer(server.NewRootHandler(db, tmpd, key, mail.Nil, "")), done
}
Beispiel #2
0
func exec() {
	scfg := config.Server
	db, err := db.NewBoltDB(scfg.Database)
	if err != nil {
		log.Fatal(err)
	}
	defer db.Close()

	smtpAuth := smtp.PlainAuth("", config.Mail.Username, config.Mail.Password, config.Mail.Server)
	mailer := mail.NewMailer(config.Mail.Server, config.Mail.Username, smtpAuth)

	handler := server.NewRootHandler(db, ".", []byte(scfg.SessionKey), mailer, scfg.URLRoot)
	if scfg.TLSCert != "" && scfg.TLSKey != "" && len(scfg.SessionKey) == 32 {
		CSRF := csrf.Protect([]byte(scfg.SessionKey))
		log.Fatal(http.ListenAndServeTLS(":"+scfg.Port, scfg.TLSCert, scfg.TLSKey, CSRF(handler)))
	} else {
		log.Fatal(http.ListenAndServe(":"+scfg.Port, handler))
	}
}