config_test.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //
  2. // Copyright (C) 2017-2018 Marcus Rohrmoser, http://purl.mro.name/ShaarliGo
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. //
  17. package main
  18. import (
  19. "golang.org/x/crypto/bcrypt"
  20. "github.com/stretchr/testify/assert"
  21. "testing"
  22. )
  23. func TestBcrypt(t *testing.T) {
  24. t.Parallel()
  25. pwd := "123456789012"
  26. hash, err := bcrypt.GenerateFromPassword([]byte(pwd), bcrypt.DefaultCost)
  27. assert.Nil(t, err, "soso")
  28. str := string(hash)
  29. err = bcrypt.CompareHashAndPassword([]byte(str), []byte(pwd))
  30. assert.Nil(t, err, "soso")
  31. err = bcrypt.CompareHashAndPassword([]byte(str), []byte("wrong"))
  32. assert.NotNil(t, err, "soso")
  33. }
  34. func TestXmlBaseFromRequestURL(t *testing.T) {
  35. t.Parallel()
  36. assert.Equal(t, "http://example.com/", xmlBaseFromRequestURL(mustParseURL("http://example.com/shaarligo.cgi"), "/shaarligo.cgi").String(), "soso")
  37. assert.Equal(t, "http://example.com/b/", xmlBaseFromRequestURL(mustParseURL("http://example.com/b/shaarligo.cgi"), "/b/shaarligo.cgi").String(), "soso")
  38. assert.Equal(t, "http://example.com/b/", xmlBaseFromRequestURL(mustParseURL("http://example.com/b/shaarligo.cgi/tools/?post=http://example.com/b/shaarligo.cgi/tools"), "/b/shaarligo.cgi").String(), "soso")
  39. }
  40. func TestLoadFeedSeed(t *testing.T) {
  41. t.Parallel()
  42. feed, err := FeedFromFileName("testdata/config-feed-seed.xml")
  43. assert.Nil(t, err, "soso")
  44. assert.Equal(t, "Seed entries for new feeds", feed.Title.Body, "soso")
  45. assert.Equal(t, 3, len(feed.Entries), "soso")
  46. assert.Equal(t, "Hello, #Atom!", feed.Entries[0].Title.Body, "soso")
  47. assert.Equal(t, "Was noch alles fehlt", feed.Entries[1].Title.Body, "soso")
  48. assert.Equal(t, "Shaarli — sebsauvage.net", feed.Entries[2].Title.Body, "soso")
  49. }