config_test.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //
  2. // Copyright (C) 2017-2021 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 TestLoadFeedSeed(t *testing.T) {
  35. t.Parallel()
  36. feed, err := FeedFromFileName("testdata/config-feed-seed.xml")
  37. assert.Nil(t, err, "soso")
  38. assert.Equal(t, "Seed entries for new feeds", feed.Title.Body, "soso")
  39. assert.Equal(t, 3, len(feed.Entries), "soso")
  40. assert.Equal(t, "Hello, #Atom!", feed.Entries[0].Title.Body, "soso")
  41. assert.Equal(t, "Was noch alles fehlt", feed.Entries[1].Title.Body, "soso")
  42. assert.Equal(t, "Shaarli — sebsauvage.net", feed.Entries[2].Title.Body, "soso")
  43. }