Tapir provides a framework for building Anonymous / metadata resistant Services
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
1.9 KiB

  1. package applications
  2. import (
  3. "crypto/rand"
  4. "cwtch.im/tapir"
  5. "cwtch.im/tapir/primitives"
  6. "encoding/json"
  7. "golang.org/x/crypto/ed25519"
  8. "testing"
  9. )
  10. type MockConnection struct {
  11. id primitives.Identity
  12. outbound bool
  13. }
  14. func (mc *MockConnection) Init(outbound bool) {
  15. mc.id, _ = primitives.InitializeEphemeralIdentity()
  16. mc.outbound = outbound
  17. return
  18. }
  19. func (mc MockConnection) Hostname() string {
  20. return mc.id.Hostname()
  21. }
  22. func (mc MockConnection) IsOutbound() bool {
  23. return mc.outbound
  24. }
  25. func (mc MockConnection) ID() *primitives.Identity {
  26. return &mc.id
  27. }
  28. func (mc MockConnection) Expect() []byte {
  29. longTermPubKey := ed25519.PublicKey(mc.id.PublicKeyBytes())
  30. epk, _, _ := ed25519.GenerateKey(rand.Reader)
  31. ephemeralPublicKey := ed25519.PublicKey(epk)
  32. //ephemeralPrivateKey := ed25519.PrivateKey(esk)
  33. //ephemeralIdentity := identity.InitializeV3("", &ephemeralPrivateKey, &ephemeralPublicKey)
  34. authMessage := AuthMessage{LongTermPublicKey: longTermPubKey, EphemeralPublicKey: ephemeralPublicKey}
  35. serialized, _ := json.Marshal(authMessage)
  36. return serialized
  37. }
  38. func (MockConnection) SetHostname(hostname string) {
  39. panic("implement me")
  40. }
  41. func (MockConnection) HasCapability(name tapir.Capability) bool {
  42. panic("implement me")
  43. }
  44. func (MockConnection) SetCapability(name tapir.Capability) {
  45. panic("implement me")
  46. }
  47. func (MockConnection) SetEncryptionKey(key [32]byte) {
  48. // no op
  49. }
  50. func (MockConnection) Send(message []byte) {
  51. // no op
  52. }
  53. func (MockConnection) Close() {
  54. // no op
  55. }
  56. func (MockConnection) App() tapir.Application {
  57. // no op
  58. return nil
  59. }
  60. func (MockConnection) SetApp(tapir.Application) {
  61. // no op
  62. }
  63. func (MockConnection) IsClosed() bool {
  64. panic("implement me")
  65. }
  66. func (MockConnection) Broadcast(message []byte, capability tapir.Capability) error {
  67. panic("implement me")
  68. }
  69. func TestAuthApp_Failed(t *testing.T) {
  70. var authApp AuthApp
  71. ai := authApp.NewInstance()
  72. mc := new(MockConnection)
  73. mc.Init(true)
  74. ai.Init(mc)
  75. }