db_test.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package authority
  2. import (
  3. "crypto/x509"
  4. "github.com/smallstep/certificates/db"
  5. "golang.org/x/crypto/ssh"
  6. )
  7. type MockAuthDB struct {
  8. err error
  9. ret1 interface{}
  10. isRevoked func(string) (bool, error)
  11. isSSHRevoked func(string) (bool, error)
  12. revoke func(rci *db.RevokedCertificateInfo) error
  13. revokeSSH func(rci *db.RevokedCertificateInfo) error
  14. storeCertificate func(crt *x509.Certificate) error
  15. useToken func(id, tok string) (bool, error)
  16. isSSHHost func(principal string) (bool, error)
  17. storeSSHCertificate func(crt *ssh.Certificate) error
  18. getSSHHostPrincipals func() ([]string, error)
  19. shutdown func() error
  20. }
  21. func (m *MockAuthDB) IsRevoked(sn string) (bool, error) {
  22. if m.isRevoked != nil {
  23. return m.isRevoked(sn)
  24. }
  25. return m.ret1.(bool), m.err
  26. }
  27. func (m *MockAuthDB) IsSSHRevoked(sn string) (bool, error) {
  28. if m.isSSHRevoked != nil {
  29. return m.isSSHRevoked(sn)
  30. }
  31. return m.ret1.(bool), m.err
  32. }
  33. func (m *MockAuthDB) UseToken(id, tok string) (bool, error) {
  34. if m.useToken != nil {
  35. return m.useToken(id, tok)
  36. }
  37. if m.ret1 == nil {
  38. return false, m.err
  39. }
  40. return m.ret1.(bool), m.err
  41. }
  42. func (m *MockAuthDB) Revoke(rci *db.RevokedCertificateInfo) error {
  43. if m.revoke != nil {
  44. return m.revoke(rci)
  45. }
  46. return m.err
  47. }
  48. func (m *MockAuthDB) RevokeSSH(rci *db.RevokedCertificateInfo) error {
  49. if m.revokeSSH != nil {
  50. return m.revokeSSH(rci)
  51. }
  52. return m.err
  53. }
  54. func (m *MockAuthDB) StoreCertificate(crt *x509.Certificate) error {
  55. if m.storeCertificate != nil {
  56. return m.storeCertificate(crt)
  57. }
  58. return m.err
  59. }
  60. func (m *MockAuthDB) IsSSHHost(principal string) (bool, error) {
  61. if m.isSSHHost != nil {
  62. return m.isSSHHost(principal)
  63. }
  64. return m.ret1.(bool), m.err
  65. }
  66. func (m *MockAuthDB) StoreSSHCertificate(crt *ssh.Certificate) error {
  67. if m.storeSSHCertificate != nil {
  68. return m.storeSSHCertificate(crt)
  69. }
  70. return m.err
  71. }
  72. func (m *MockAuthDB) GetSSHHostPrincipals() ([]string, error) {
  73. if m.getSSHHostPrincipals != nil {
  74. return m.getSSHHostPrincipals()
  75. }
  76. return m.ret1.([]string), m.err
  77. }
  78. func (m *MockAuthDB) Shutdown() error {
  79. if m.shutdown != nil {
  80. return m.shutdown()
  81. }
  82. return m.err
  83. }