Browse Source

Move go server into docker container and start adding tests

pull/4/head
Tovi Jaeschke-Rogers 2 years ago
parent
commit
b914a9f75c
70 changed files with 740 additions and 227 deletions
  1. +3
    -3
      Backend/Api/Auth/AddProfileImage.go
  2. +2
    -2
      Backend/Api/Auth/ChangeMessageExpiry.go
  3. +2
    -2
      Backend/Api/Auth/ChangePassword.go
  4. +2
    -2
      Backend/Api/Auth/Login.go
  5. +140
    -0
      Backend/Api/Auth/Login_test.go
  6. +5
    -2
      Backend/Api/Auth/Logout.go
  7. +131
    -0
      Backend/Api/Auth/Logout_test.go
  8. +3
    -3
      Backend/Api/Auth/Session.go
  9. +30
    -58
      Backend/Api/Auth/Signup.go
  10. +168
    -0
      Backend/Api/Auth/Signup_test.go
  11. +2
    -2
      Backend/Api/Friends/AcceptFriendRequest.go
  12. +3
    -3
      Backend/Api/Friends/EncryptedFriendsList.go
  13. +3
    -3
      Backend/Api/Friends/FriendRequest.go
  14. +2
    -2
      Backend/Api/Friends/Friends.go
  15. +2
    -2
      Backend/Api/Friends/RejectFriendRequest.go
  16. +1
    -1
      Backend/Api/JsonSerialization/DeserializeUserJson.go
  17. +3
    -3
      Backend/Api/Messages/AddConversationImage.go
  18. +3
    -3
      Backend/Api/Messages/Conversations.go
  19. +2
    -2
      Backend/Api/Messages/CreateConversation.go
  20. +3
    -3
      Backend/Api/Messages/CreateMessage.go
  21. +2
    -2
      Backend/Api/Messages/MessageThread.go
  22. +2
    -2
      Backend/Api/Messages/UpdateConversation.go
  23. +4
    -4
      Backend/Api/Routes.go
  24. +2
    -2
      Backend/Api/Users/SearchUsers.go
  25. +1
    -1
      Backend/Database/Attachments.go
  26. +1
    -1
      Backend/Database/ConversationDetailUsers.go
  27. +1
    -1
      Backend/Database/ConversationDetails.go
  28. +1
    -1
      Backend/Database/FriendRequests.go
  29. +3
    -3
      Backend/Database/Init.go
  30. +1
    -1
      Backend/Database/MessageData.go
  31. +1
    -1
      Backend/Database/Messages.go
  32. +7
    -7
      Backend/Database/Seeder/FriendSeeder.go
  33. +8
    -8
      Backend/Database/Seeder/MessageSeeder.go
  34. +39
    -16
      Backend/Database/Seeder/Seed.go
  35. +7
    -7
      Backend/Database/Seeder/UserSeeder.go
  36. +2
    -2
      Backend/Database/Seeder/encryption.go
  37. +12
    -4
      Backend/Database/Sessions.go
  38. +1
    -1
      Backend/Database/UserConversations.go
  39. +1
    -1
      Backend/Database/Users.go
  40. +16
    -0
      Backend/Dockerfile
  41. +2
    -2
      Backend/Util/UserHelper.go
  42. +1
    -1
      Backend/go.mod
  43. +3
    -3
      Backend/main.go
  44. +1
    -1
      README.md
  45. +49
    -0
      docker-compose.yml
  46. +1
    -1
      mobile/android/app/src/main/AndroidManifest.xml
  47. +2
    -2
      mobile/lib/components/view_image.dart
  48. +1
    -1
      mobile/lib/main.dart
  49. +2
    -2
      mobile/lib/models/conversation_users.dart
  50. +2
    -2
      mobile/lib/models/conversations.dart
  51. +3
    -3
      mobile/lib/models/image_message.dart
  52. +1
    -1
      mobile/lib/models/my_profile.dart
  53. +2
    -2
      mobile/lib/utils/storage/conversations.dart
  54. +2
    -2
      mobile/lib/utils/storage/database.dart
  55. +2
    -2
      mobile/lib/utils/storage/messages.dart
  56. +1
    -1
      mobile/lib/views/authentication/login.dart
  57. +3
    -3
      mobile/lib/views/authentication/signup.dart
  58. +1
    -1
      mobile/lib/views/authentication/unauthenticated_landing.dart
  59. +2
    -2
      mobile/lib/views/main/conversation/create_add_users_list.dart
  60. +1
    -1
      mobile/lib/views/main/conversation/detail.dart
  61. +1
    -1
      mobile/lib/views/main/conversation/edit_details.dart
  62. +3
    -3
      mobile/lib/views/main/conversation/list.dart
  63. +4
    -4
      mobile/lib/views/main/conversation/message.dart
  64. +7
    -7
      mobile/lib/views/main/conversation/settings.dart
  65. +4
    -4
      mobile/lib/views/main/friend/list.dart
  66. +6
    -6
      mobile/lib/views/main/friend/list_item.dart
  67. +1
    -1
      mobile/lib/views/main/profile/change_server_url.dart
  68. +5
    -5
      mobile/lib/views/main/profile/profile.dart
  69. +2
    -2
      mobile/pubspec.yaml
  70. +3
    -0
      test.sh

+ 3
- 3
Backend/Api/Auth/AddProfileImage.go View File

@ -5,9 +5,9 @@ import (
"encoding/json"
"net/http"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Database"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Models"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Util"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Database"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Models"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Util"
)
// AddProfileImage adds a profile image


+ 2
- 2
Backend/Api/Auth/ChangeMessageExpiry.go View File

@ -5,8 +5,8 @@ import (
"io/ioutil"
"net/http"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Database"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Models"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Database"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Models"
)
type rawChangeMessageExpiry struct {


+ 2
- 2
Backend/Api/Auth/ChangePassword.go View File

@ -5,8 +5,8 @@ import (
"io/ioutil"
"net/http"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Database"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Models"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Database"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Models"
)
type rawChangePassword struct {


+ 2
- 2
Backend/Api/Auth/Login.go View File

@ -6,8 +6,8 @@ import (
"net/http"
"time"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Database"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Models"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Database"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Models"
)
type credentials struct {


+ 140
- 0
Backend/Api/Auth/Login_test.go View File

@ -0,0 +1,140 @@
package Auth_test
import (
"bytes"
"encoding/base64"
"encoding/json"
"io/ioutil"
"log"
"net/http"
"net/http/httptest"
"testing"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Api"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Api/Auth"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Database"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Database/Seeder"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Models"
"github.com/gorilla/mux"
)
func Test_Login(t *testing.T) {
log.SetOutput(ioutil.Discard)
Database.InitTest()
r := mux.NewRouter()
Api.InitAPIEndpoints(r)
ts := httptest.NewServer(r)
defer ts.Close()
userKey, _ := Seeder.GenerateAesKey()
pubKey := Seeder.GetPubKey()
p, _ := Auth.HashPassword("password")
u := Models.User{
Username: "test",
Password: p,
AsymmetricPublicKey: Seeder.PublicKey,
AsymmetricPrivateKey: Seeder.EncryptedPrivateKey,
SymmetricKey: base64.StdEncoding.EncodeToString(
Seeder.EncryptWithPublicKey(userKey.Key, pubKey),
),
}
err := Database.CreateUser(&u)
if err != nil {
t.Errorf("Expected nil, recieved %s", err.Error())
return
}
d := struct {
Username string `json:"username"`
Password string `json:"password"`
}{
Username: "test",
Password: "password",
}
jsonStr, _ := json.Marshal(d)
req, _ := http.NewRequest("POST", ts.URL+"/api/v1/login", bytes.NewBuffer(jsonStr))
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
t.Errorf("Expected nil, recieved %s", err.Error())
return
}
if resp.StatusCode != http.StatusOK {
t.Errorf("Expected %d, recieved %d", http.StatusOK, resp.StatusCode)
return
}
var session Models.Session
err = Database.DB.First(&session, "user_id = ?", u.ID.String()).Error
if err != nil {
t.Errorf("Expected user record, recieved %s", err.Error())
return
}
}
func Test_Login_PasswordFails(t *testing.T) {
log.SetOutput(ioutil.Discard)
Database.InitTest()
r := mux.NewRouter()
Api.InitAPIEndpoints(r)
ts := httptest.NewServer(r)
defer ts.Close()
userKey, _ := Seeder.GenerateAesKey()
pubKey := Seeder.GetPubKey()
p, _ := Auth.HashPassword("password")
u := Models.User{
Username: "test",
Password: p,
AsymmetricPublicKey: Seeder.PublicKey,
AsymmetricPrivateKey: Seeder.EncryptedPrivateKey,
SymmetricKey: base64.StdEncoding.EncodeToString(
Seeder.EncryptWithPublicKey(userKey.Key, pubKey),
),
}
err := Database.CreateUser(&u)
if err != nil {
t.Errorf("Expected nil, recieved %s", err.Error())
return
}
d := struct {
Username string `json:"username"`
Password string `json:"password"`
}{
Username: "test",
Password: "password1",
}
jsonStr, _ := json.Marshal(d)
req, _ := http.NewRequest("POST", ts.URL+"/api/v1/login", bytes.NewBuffer(jsonStr))
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
t.Errorf("Expected nil, recieved %s", err.Error())
return
}
if resp.StatusCode != http.StatusUnauthorized {
t.Errorf("Expected %d, recieved %d", http.StatusUnauthorized, resp.StatusCode)
return
}
}

+ 5
- 2
Backend/Api/Auth/Logout.go View File

@ -5,9 +5,10 @@ import (
"net/http"
"time"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Database"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Database"
)
// Logout logs out from system
func Logout(w http.ResponseWriter, r *http.Request) {
var (
c *http.Cookie
@ -27,7 +28,7 @@ func Logout(w http.ResponseWriter, r *http.Request) {
sessionToken = c.Value
err = Database.DeleteSessionById(sessionToken)
err = Database.DeleteSessionByID(sessionToken)
if err != nil {
log.Println("Could not delete session cookie")
}
@ -37,4 +38,6 @@ func Logout(w http.ResponseWriter, r *http.Request) {
Value: "",
Expires: time.Now(),
})
w.WriteHeader(http.StatusOK)
}

+ 131
- 0
Backend/Api/Auth/Logout_test.go View File

@ -0,0 +1,131 @@
package Auth_test
import (
"bytes"
"encoding/base64"
"encoding/json"
"io/ioutil"
"log"
"net/http"
"net/http/cookiejar"
"net/http/httptest"
"net/url"
"sync"
"testing"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Api"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Api/Auth"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Database"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Database/Seeder"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Models"
"github.com/gorilla/mux"
)
type Jar struct {
lk sync.Mutex
cookies map[string][]*http.Cookie
}
func Test_Logout(t *testing.T) {
log.SetOutput(ioutil.Discard)
Database.InitTest()
r := mux.NewRouter()
Api.InitAPIEndpoints(r)
ts := httptest.NewServer(r)
defer ts.Close()
userKey, _ := Seeder.GenerateAesKey()
pubKey := Seeder.GetPubKey()
p, _ := Auth.HashPassword("password")
u := Models.User{
Username: "test",
Password: p,
AsymmetricPublicKey: Seeder.PublicKey,
AsymmetricPrivateKey: Seeder.EncryptedPrivateKey,
SymmetricKey: base64.StdEncoding.EncodeToString(
Seeder.EncryptWithPublicKey(userKey.Key, pubKey),
),
}
err := Database.CreateUser(&u)
if err != nil {
t.Errorf("Expected nil, recieved %s", err.Error())
return
}
d := struct {
Username string `json:"username"`
Password string `json:"password"`
}{
Username: "test",
Password: "password",
}
jsonStr, _ := json.Marshal(d)
req, _ := http.NewRequest("POST", ts.URL+"/api/v1/login", bytes.NewBuffer(jsonStr))
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
t.Errorf("Expected nil, recieved %s", err.Error())
return
}
if resp.StatusCode != http.StatusOK {
t.Errorf("Expected %d, recieved %d", http.StatusOK, resp.StatusCode)
return
}
var session Models.Session
err = Database.DB.First(&session, "user_id = ?", u.ID.String()).Error
if err != nil {
t.Errorf("Expected session record, recieved %s", err.Error())
return
}
jar, err := cookiejar.New(nil)
if err != nil {
t.Errorf("Expected nil, recieved %s", err.Error())
}
url, _ := url.Parse(ts.URL)
jar.SetCookies(
url,
[]*http.Cookie{
&http.Cookie{
Name: "session_token",
Value: session.ID.String(),
MaxAge: 300,
},
},
)
client = &http.Client{
Jar: jar,
}
resp, err = client.Get(ts.URL + "/api/v1/logout")
if err != nil {
t.Errorf("Expected user record, recieved %s", err.Error())
return
}
if resp.StatusCode != http.StatusOK {
t.Errorf("Expected %d, recieved %d", http.StatusOK, resp.StatusCode)
return
}
err = Database.DB.First(&session, "user_id = ?", u.ID.String()).Error
if err == nil {
t.Errorf("Expected no session record, recieved %s", session.UserID)
return
}
}

+ 3
- 3
Backend/Api/Auth/Session.go View File

@ -4,8 +4,8 @@ import (
"errors"
"net/http"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Database"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Models"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Database"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Models"
)
func CheckCookie(r *http.Request) (Models.Session, error) {
@ -23,7 +23,7 @@ func CheckCookie(r *http.Request) (Models.Session, error) {
sessionToken = c.Value
// We then get the session from our session map
userSession, err = Database.GetSessionById(sessionToken)
userSession, err = Database.GetSessionByID(sessionToken)
if err != nil {
return userSession, errors.New("Cookie not found")
}


+ 30
- 58
Backend/Api/Auth/Signup.go View File

@ -2,95 +2,67 @@ package Auth
import (
"encoding/json"
"io/ioutil"
"log"
"net/http"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Api/JsonSerialization"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Database"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Models"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Database"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Models"
)
type signupResponse struct {
Status string `json:"status"`
Message string `json:"message"`
}
func makeSignupResponse(w http.ResponseWriter, code int, message string) {
var (
status = "error"
returnJSON []byte
err error
)
if code > 200 && code < 300 {
status = "success"
}
returnJSON, err = json.MarshalIndent(signupResponse{
Status: status,
Message: message,
}, "", " ")
if err != nil {
http.Error(w, "Error", http.StatusInternalServerError)
return
}
// Return updated json
w.WriteHeader(code)
w.Write(returnJSON)
type signup struct {
Username string `json:"username"`
Password string `json:"password"`
ConfirmPassword string `json:"confirm_password"`
PublicKey string `json:"asymmetric_public_key"`
PrivateKey string `json:"asymmetric_private_key"`
SymmetricKey string `json:"symmetric_key"`
}
// Signup to the platform
func Signup(w http.ResponseWriter, r *http.Request) {
var (
userData Models.User
requestBody []byte
err error
user Models.User
err error
)
requestBody, err = ioutil.ReadAll(r.Body)
err = json.NewDecoder(r.Body).Decode(&user)
if err != nil {
log.Printf("Error encountered reading POST body: %s\n", err.Error())
makeSignupResponse(w, http.StatusInternalServerError, "An error occurred")
http.Error(w, "Invalid Data", http.StatusUnprocessableEntity)
return
}
userData, err = JsonSerialization.DeserializeUser(requestBody, []string{
"id",
}, false)
if err != nil {
log.Printf("Invalid data provided to Signup: %s\n", err.Error())
makeSignupResponse(w, http.StatusUnprocessableEntity, "Invalid data provided")
if user.Username == "" ||
user.Password == "" ||
user.ConfirmPassword == "" ||
len(user.AsymmetricPrivateKey) == 0 ||
len(user.AsymmetricPublicKey) == 0 ||
len(user.SymmetricKey) == 0 {
http.Error(w, "Invalid Data", http.StatusUnprocessableEntity)
return
}
if userData.Username == "" ||
userData.Password == "" ||
userData.ConfirmPassword == "" ||
len(userData.AsymmetricPrivateKey) == 0 ||
len(userData.AsymmetricPublicKey) == 0 {
makeSignupResponse(w, http.StatusUnprocessableEntity, "Invalid data provided")
if user.Password != user.ConfirmPassword {
http.Error(w, "Invalid Data", http.StatusUnprocessableEntity)
return
}
err = Database.CheckUniqueUsername(userData.Username)
err = Database.CheckUniqueUsername(user.Username)
if err != nil {
makeSignupResponse(w, http.StatusUnprocessableEntity, "Invalid data provided")
http.Error(w, "Invalid Data", http.StatusUnprocessableEntity)
return
}
userData.Password, err = HashPassword(userData.Password)
user.Password, err = HashPassword(user.Password)
if err != nil {
makeSignupResponse(w, http.StatusInternalServerError, "An error occurred")
http.Error(w, "Error", http.StatusInternalServerError)
return
}
err = Database.CreateUser(&userData)
err = Database.CreateUser(&user)
if err != nil {
makeSignupResponse(w, http.StatusInternalServerError, "An error occurred")
http.Error(w, "Error", http.StatusInternalServerError)
return
}
makeSignupResponse(w, http.StatusCreated, "Successfully signed up")
w.WriteHeader(http.StatusNoContent)
}

+ 168
- 0
Backend/Api/Auth/Signup_test.go View File

@ -0,0 +1,168 @@
package Auth_test
import (
"bytes"
"encoding/base64"
"encoding/json"
"io/ioutil"
"log"
"net/http"
"net/http/httptest"
"testing"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Api"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Database"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Database/Seeder"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Models"
"github.com/gorilla/mux"
)
func Test_Signup(t *testing.T) {
log.SetOutput(ioutil.Discard)
Database.InitTest()
r := mux.NewRouter()
Api.InitAPIEndpoints(r)
ts := httptest.NewServer(r)
defer ts.Close()
userKey, _ := Seeder.GenerateAesKey()
pubKey := Seeder.GetPubKey()
d := struct {
Username string `json:"username"`
Password string `json:"password"`
ConfirmPassword string `json:"confirm_password"`
PubKey string `json:"asymmetric_public_key"`
PrivKey string `json:"asymmetric_private_key"`
SymKey string `json:"symmetric_key"`
}{
Username: "test",
Password: "password",
ConfirmPassword: "password",
PubKey: Seeder.PublicKey,
PrivKey: Seeder.EncryptedPrivateKey,
SymKey: base64.StdEncoding.EncodeToString(
Seeder.EncryptWithPublicKey(userKey.Key, pubKey),
),
}
jsonStr, _ := json.Marshal(d)
req, _ := http.NewRequest("POST", ts.URL+"/api/v1/signup", bytes.NewBuffer(jsonStr))
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
t.Errorf("Expected nil, recieved %s", err.Error())
return
}
if resp.StatusCode != http.StatusNoContent {
t.Errorf("Expected %d, recieved %d", http.StatusNoContent, resp.StatusCode)
return
}
var user Models.User
err = Database.DB.First(&user, "username = ?", "test").Error
if err != nil {
t.Errorf("Expected user record, recieved %s", err.Error())
return
}
}
func Test_Signup_PasswordMismatchFails(t *testing.T) {
log.SetOutput(ioutil.Discard)
Database.InitTest()
r := mux.NewRouter()
Api.InitAPIEndpoints(r)
ts := httptest.NewServer(r)
defer ts.Close()
userKey, _ := Seeder.GenerateAesKey()
pubKey := Seeder.GetPubKey()
d := struct {
Username string `json:"username"`
Password string `json:"password"`
ConfirmPassword string `json:"confirm_password"`
PubKey string `json:"asymmetric_public_key"`
PrivKey string `json:"asymmetric_private_key"`
SymKey string `json:"symmetric_key"`
}{
Username: "test",
Password: "password",
ConfirmPassword: "password1",
PubKey: Seeder.PublicKey,
PrivKey: Seeder.EncryptedPrivateKey,
SymKey: base64.StdEncoding.EncodeToString(
Seeder.EncryptWithPublicKey(userKey.Key, pubKey),
),
}
jsonStr, _ := json.Marshal(d)
req, _ := http.NewRequest("POST", ts.URL+"/api/v1/signup", bytes.NewBuffer(jsonStr))
req.Header.Set("X-Custom-Header", "myvalue")
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
t.Errorf("Expected nil, recieved %s", err.Error())
return
}
if resp.StatusCode != http.StatusUnprocessableEntity {
t.Errorf("Expected %d, recieved %d", http.StatusUnprocessableEntity, resp.StatusCode)
return
}
}
func Test_Signup_MissingDataFails(t *testing.T) {
log.SetOutput(ioutil.Discard)
Database.InitTest()
r := mux.NewRouter()
Api.InitAPIEndpoints(r)
ts := httptest.NewServer(r)
defer ts.Close()
d := struct {
Username string `json:"username"`
Password string `json:"password"`
ConfirmPassword string `json:"confirm_password"`
PubKey string `json:"asymmetric_public_key"`
PrivKey string `json:"asymmetric_private_key"`
SymKey string `json:"symmetric_key"`
}{
Username: "test",
Password: "password",
ConfirmPassword: "password",
PubKey: "",
PrivKey: "",
SymKey: "",
}
jsonStr, _ := json.Marshal(d)
req, _ := http.NewRequest("POST", ts.URL+"/api/v1/signup", bytes.NewBuffer(jsonStr))
req.Header.Set("X-Custom-Header", "myvalue")
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
t.Errorf("Expected nil, recieved %s", err.Error())
}
if resp.StatusCode != http.StatusUnprocessableEntity {
t.Errorf("Expected %d, recieved %d", http.StatusUnprocessableEntity, resp.StatusCode)
}
}

+ 2
- 2
Backend/Api/Friends/AcceptFriendRequest.go View File

@ -6,8 +6,8 @@ import (
"net/http"
"time"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Database"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Models"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Database"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Models"
"github.com/gorilla/mux"
)


+ 3
- 3
Backend/Api/Friends/EncryptedFriendsList.go View File

@ -4,9 +4,9 @@ import (
"encoding/json"
"net/http"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Api/Auth"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Database"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Models"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Api/Auth"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Database"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Models"
)
// EncryptedFriendRequestList gets friend request list


+ 3
- 3
Backend/Api/Friends/FriendRequest.go View File

@ -5,9 +5,9 @@ import (
"io/ioutil"
"net/http"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Database"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Models"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Util"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Database"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Models"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Util"
)
func FriendRequest(w http.ResponseWriter, r *http.Request) {


+ 2
- 2
Backend/Api/Friends/Friends.go View File

@ -6,8 +6,8 @@ import (
"net/http"
"time"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Database"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Models"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Database"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Models"
)
// CreateFriendRequest creates a FriendRequest from post data


+ 2
- 2
Backend/Api/Friends/RejectFriendRequest.go View File

@ -3,8 +3,8 @@ package Friends
import (
"net/http"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Database"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Models"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Database"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Models"
"github.com/gorilla/mux"
)


+ 1
- 1
Backend/Api/JsonSerialization/DeserializeUserJson.go View File

@ -6,7 +6,7 @@ import (
"fmt"
"strings"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Models"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Models"
schema "github.com/Kangaroux/go-map-schema"
)


+ 3
- 3
Backend/Api/Messages/AddConversationImage.go View File

@ -5,9 +5,9 @@ import (
"encoding/json"
"net/http"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Database"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Models"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Util"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Database"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Models"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Util"
"github.com/gorilla/mux"
)


+ 3
- 3
Backend/Api/Messages/Conversations.go View File

@ -6,9 +6,9 @@ import (
"net/url"
"strings"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Api/Auth"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Database"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Models"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Api/Auth"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Database"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Models"
)
// EncryptedConversationList returns an encrypted list of all Conversations


+ 2
- 2
Backend/Api/Messages/CreateConversation.go View File

@ -6,8 +6,8 @@ import (
"github.com/gofrs/uuid"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Database"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Models"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Database"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Models"
)
// RawCreateConversationData for holding POST payload


+ 3
- 3
Backend/Api/Messages/CreateMessage.go View File

@ -5,9 +5,9 @@ import (
"encoding/json"
"net/http"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Database"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Models"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Util"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Database"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Models"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Util"
)
type rawMessageData struct {


+ 2
- 2
Backend/Api/Messages/MessageThread.go View File

@ -4,8 +4,8 @@ import (
"encoding/json"
"net/http"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Database"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Models"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Database"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Models"
"github.com/gorilla/mux"
)


+ 2
- 2
Backend/Api/Messages/UpdateConversation.go View File

@ -6,8 +6,8 @@ import (
"github.com/gofrs/uuid"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Database"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Models"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Database"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Models"
)
type rawUpdateConversationData struct {


+ 4
- 4
Backend/Api/Routes.go View File

@ -4,10 +4,10 @@ import (
"log"
"net/http"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Api/Auth"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Api/Friends"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Api/Messages"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Api/Users"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Api/Auth"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Api/Friends"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Api/Messages"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Api/Users"
"github.com/gorilla/mux"
)


+ 2
- 2
Backend/Api/Users/SearchUsers.go View File

@ -5,8 +5,8 @@ import (
"net/http"
"net/url"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Database"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Models"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Database"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Models"
)
// SearchUsers searches a for a user by username


+ 1
- 1
Backend/Database/Attachments.go View File

@ -1,7 +1,7 @@
package Database
import (
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Models"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Models"
"gorm.io/gorm"
"gorm.io/gorm/clause"


+ 1
- 1
Backend/Database/ConversationDetailUsers.go View File

@ -1,7 +1,7 @@
package Database
import (
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Models"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Models"
"gorm.io/gorm"
"gorm.io/gorm/clause"


+ 1
- 1
Backend/Database/ConversationDetails.go View File

@ -1,7 +1,7 @@
package Database
import (
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Models"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Models"
"gorm.io/gorm"
"gorm.io/gorm/clause"


+ 1
- 1
Backend/Database/FriendRequests.go View File

@ -1,7 +1,7 @@
package Database
import (
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Models"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Models"
"gorm.io/gorm"
"gorm.io/gorm/clause"


+ 3
- 3
Backend/Database/Init.go View File

@ -3,15 +3,15 @@ package Database
import (
"log"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Models"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Models"
"gorm.io/driver/postgres"
"gorm.io/gorm"
)
const (
dbURL = "postgres://postgres:@localhost:5432/envelope"
dbTestURL = "postgres://postgres:@localhost:5432/envelope_test"
dbURL = "postgres://postgres:password@postgres:5432/capsule"
dbTestURL = "postgres://postgres:password@postgres-testing:5432/capsule-testing"
)
// DB db


+ 1
- 1
Backend/Database/MessageData.go View File

@ -1,7 +1,7 @@
package Database
import (
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Models"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Models"
"gorm.io/gorm"
"gorm.io/gorm/clause"


+ 1
- 1
Backend/Database/Messages.go View File

@ -1,7 +1,7 @@
package Database
import (
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Models"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Models"
"gorm.io/gorm"
"gorm.io/gorm/clause"


+ 7
- 7
Backend/Database/Seeder/FriendSeeder.go View File

@ -6,8 +6,8 @@ import (
"os"
"time"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Database"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Models"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Database"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Models"
)
func seedFriend(userRequestTo, userRequestFrom Models.User, accepted bool) error {
@ -18,12 +18,12 @@ func seedFriend(userRequestTo, userRequestFrom Models.User, accepted bool) error
err error
)
symKey, err = generateAesKey()
symKey, err = GenerateAesKey()
if err != nil {
return err
}
encPublicKey, err = symKey.aesEncrypt([]byte(publicKey))
encPublicKey, err = symKey.aesEncrypt([]byte(PublicKey))
if err != nil {
return err
}
@ -31,13 +31,13 @@ func seedFriend(userRequestTo, userRequestFrom Models.User, accepted bool) error
friendRequest = Models.FriendRequest{
UserID: userRequestTo.ID,
FriendID: base64.StdEncoding.EncodeToString(
encryptWithPublicKey(
EncryptWithPublicKey(
[]byte(userRequestFrom.ID.String()),
decodedPublicKey,
),
),
FriendUsername: base64.StdEncoding.EncodeToString(
encryptWithPublicKey(
EncryptWithPublicKey(
[]byte(userRequestFrom.Username),
decodedPublicKey,
),
@ -46,7 +46,7 @@ func seedFriend(userRequestTo, userRequestFrom Models.User, accepted bool) error
encPublicKey,
),
SymmetricKey: base64.StdEncoding.EncodeToString(
encryptWithPublicKey(symKey.Key, decodedPublicKey),
EncryptWithPublicKey(symKey.Key, decodedPublicKey),
),
}


+ 8
- 8
Backend/Database/Seeder/MessageSeeder.go View File

@ -3,8 +3,8 @@ package Seeder
import (
"encoding/base64"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Database"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Models"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Database"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Models"
"github.com/gofrs/uuid"
)
@ -27,12 +27,12 @@ func seedMessage(
plaintext = "Test Message"
userKey, err = generateAesKey()
userKey, err = GenerateAesKey()
if err != nil {
panic(err)
}
key, err = generateAesKey()
key, err = GenerateAesKey()
if err != nil {
panic(err)
}
@ -70,7 +70,7 @@ func seedMessage(
message = Models.Message{
MessageData: messageData,
SymmetricKey: base64.StdEncoding.EncodeToString(
encryptWithPublicKey(userKey.Key, decodedPublicKey),
EncryptWithPublicKey(userKey.Key, decodedPublicKey),
),
AssociationKey: primaryUserAssociationKey,
}
@ -83,7 +83,7 @@ func seedMessage(
message = Models.Message{
MessageData: messageData,
SymmetricKey: base64.StdEncoding.EncodeToString(
encryptWithPublicKey(userKey.Key, decodedPublicKey),
EncryptWithPublicKey(userKey.Key, decodedPublicKey),
),
AssociationKey: secondaryUserAssociationKey,
}
@ -148,7 +148,7 @@ func seedUserConversation(
ConversationDetailID: base64.StdEncoding.EncodeToString(conversationDetailIDCiphertext),
Admin: base64.StdEncoding.EncodeToString(adminCiphertext),
SymmetricKey: base64.StdEncoding.EncodeToString(
encryptWithPublicKey(key.Key, decodedPublicKey),
EncryptWithPublicKey(key.Key, decodedPublicKey),
),
}
@ -233,7 +233,7 @@ func SeedMessages() {
err error
)
key, err = generateAesKey()
key, err = GenerateAesKey()
if err != nil {
panic(err)
}


+ 39
- 16
Backend/Database/Seeder/Seed.go View File

@ -9,11 +9,11 @@ import (
)
const (
// Encrypted with "password"
encryptedPrivateKey string = `sPhQsHpXYFqPb7qdmTY7APFwBb4m7meCITujDeKMQFnIjplOVm9ijjXU+YAmGvrX13ukBj8zo9MTVhjJUjJ917pyLhl4w8uyg1jCvplUYtJVXhGA9Wy3NqHMuq3SU3fKdlEM+oR4zYkbAYWp42XvulbcuVBEWiWkvHOrbdKPFpMmd54SL2c/vcWrmjgC7rTlJf2TYICZwRK+6Y0XZi5fSWeU0vg7+rHWKHc5MHHtAdAiL+HCa90c5gfh+hXkT5ojGHOkhT9kdLy3PTPN19EGpdXgZ3WFq1z9CZ6zX7uM091uR0IvgzfwaLx8HJCx7ViWQhioH9LJZgC73RMf/dwzejg2COy4QT/E59RPOczgd779rxiRmphMoR8xJYBFRlkTVmcUO4NcUE50Cc39hXezcekHuV1YQK4BXTrxGX1ceiCXYlKAWS9wHZpog9OldTCPBpw5XAWExh3kRzqdvsdHxHVE+TpAEIjDljAlc3r+FPHYH1zWWk41eQ/zz3Vkx5Zl4dMF9x+uUOspQXVb/4K42e9fMKychNUN5o/JzIwy7xOzgXa6iwf223On/mXKV6FK6Q8lojK7Wc8g7AwfqnN9//HjI14pVqGBJtn5ggL/g4qt0JFl3pV/6n/ZLMG6k8wpsaApLGvsTPqZHcv+C69Z33rZQ4TagXVxpmnWMpPCaR0+Dawn4iAce2UvUtIN2KbJNcTtRQo4z30+BbgmVKHgkR0EHMu4cYjJPYwJ5H8IYcQuFKb7+Cp33FD2Lv54I9uvtVHH9bWcid9K82y68PufJi/0icZ3EyEqZygez9mgJzxXO1b7xZMiosGs82QRv7IIOSzqBPRYv1Lxi3fWkgnOvw4dWFxJnKEI2+KD9K0z+XsgVlm26fdRklQAAf6xOJ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YBBAKJ7Nm58C3rz832+ZTGVdQ3490TvO+sCLYKzpgtsqr8KyedG9LKa8wn/wlRD7kYn+J2SrMPY2Q0e4evyJaCAsolp/BQfy9JFtyRDPWTHn+jOHjW8ZN7vswGkRwYlSJSl0UC8mmJyS4lwnO/Vv4wBnDHQEzIycjn3JZAlV5ing0HKqUfW6G07453JXd8oZiMC/kIQjgWkdg34zxBYarVVrHFG5FIH9w7QWY8PCDU/kkcLniT0yD1/gkqAG2HpwaXEcSqX8Ofrbpd/IA7R7iCXYE5Q1mAvSvICpPg9Cf3CHjLyAEDz9cwKnZHkocXC8evdsTf2e7Wz8FFPAI3onFvym0MfZuRrIZitX1V8NOLedd3y74CwuErfzrr60DjyPRxGbJ4llMbm+ojeENe0HBedNm71jf+McSihKbSo5GDBxfVYVreYZ8A4iP0LsxtzQFxuzdeDL5KA9uNNw+LN9FN9vKhdALhQSnSfLPfMBsM/ey7dbxb4eRT0fpApX`
// Private key for testing server side
privateKey string = `-----BEGIN PRIVATE KEY-----
// PrivateKey for testing server side
PrivateKey string = `-----BEGIN PRIVATE KEY-----
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDJScQQJxWxKwqf
FmXH64QnRBVyW7cU25F+O9Zy96dqTjbV4ruWrzb4+txmK20ZPQvMxDLefhEzTXWb
HZV1P/XxgmEpaBVHwHnkhaPzzChOa/G18CDoCNrgyVzh5a31OotTCuGlS1bSkR53
@ -42,7 +42,8 @@ b0XvaLzh1iKG7HZ9tvPt/VhHlKKosNBK/j4fvgMZg7/bhRfHmaDQKoqlGbtyWjEQ
mj1b2/Gnbk3VYDR16BFfj7m2
-----END PRIVATE KEY-----`
publicKey string = `-----BEGIN PUBLIC KEY-----
// PublicKey for encryption
PublicKey string = `-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyUnEECcVsSsKnxZlx+uE
J0QVclu3FNuRfjvWcvenak421eK7lq82+PrcZittGT0LzMQy3n4RM011mx2VdT/1
8YJhKWgVR8B55IWj88woTmvxtfAg6Aja4Mlc4eWt9TqLUwrhpUtW0pEedxMT10Kv
@ -58,35 +59,57 @@ var (
decodedPrivateKey *rsa.PrivateKey
)
// Seed seeds semi random data for use in testing & development
func Seed() {
// GetPubKey for seeding & tests
func GetPubKey() *rsa.PublicKey {
var (
block *pem.Block
decKey any
ok bool
err error
block *pem.Block
decKey any
decPubKey *rsa.PublicKey
ok bool
err error
)
block, _ = pem.Decode([]byte(publicKey))
block, _ = pem.Decode([]byte(PublicKey))
decKey, err = x509.ParsePKIXPublicKey(block.Bytes)
if err != nil {
panic(err)
}
decodedPublicKey, ok = decKey.(*rsa.PublicKey)
decPubKey, ok = decKey.(*rsa.PublicKey)
if !ok {
panic(errors.New("Invalid decodedPublicKey"))
}
block, _ = pem.Decode([]byte(privateKey))
return decPubKey
}
// GetPrivKey for seeding & tests
func GetPrivKey() *rsa.PrivateKey {
var (
block *pem.Block
decKey any
decPrivKey *rsa.PrivateKey
ok bool
err error
)
block, _ = pem.Decode([]byte(PrivateKey))
decKey, err = x509.ParsePKCS8PrivateKey(block.Bytes)
if err != nil {
panic(err)
}
decodedPrivateKey, ok = decKey.(*rsa.PrivateKey)
decPrivKey, ok = decKey.(*rsa.PrivateKey)
if !ok {
panic(errors.New("Invalid decodedPrivateKey"))
}
return decPrivKey
}
// Seed seeds semi random data for use in testing & development
func Seed() {
decodedPublicKey = GetPubKey()
decodedPrivateKey = GetPrivKey()
log.Println("Seeding users...")
SeedUsers()


+ 7
- 7
Backend/Database/Seeder/UserSeeder.go View File

@ -3,9 +3,9 @@ package Seeder
import (
"encoding/base64"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Api/Auth"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Database"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Models"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Api/Auth"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Database"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Models"
)
var userNames = []string{
@ -30,7 +30,7 @@ func createUser(username string) (Models.User, error) {
err error
)
userKey, err = generateAesKey()
userKey, err = GenerateAesKey()
if err != nil {
panic(err)
}
@ -43,10 +43,10 @@ func createUser(username string) (Models.User, error) {
userData = Models.User{
Username: username,
Password: password,
AsymmetricPrivateKey: encryptedPrivateKey,
AsymmetricPublicKey: publicKey,
AsymmetricPrivateKey: EncryptedPrivateKey,
AsymmetricPublicKey: PublicKey,
SymmetricKey: base64.StdEncoding.EncodeToString(
encryptWithPublicKey(userKey.Key, decodedPublicKey),
EncryptWithPublicKey(userKey.Key, decodedPublicKey),
),
}


+ 2
- 2
Backend/Database/Seeder/encryption.go View File

@ -71,7 +71,7 @@ func pkcs7strip(data []byte, blockSize int) ([]byte, error) {
return data[:length-padLen], nil
}
func generateAesKey() (aesKey, error) {
func GenerateAesKey() (aesKey, error) {
var (
saltBytes []byte = []byte{}
password []byte
@ -157,7 +157,7 @@ func (key aesKey) aesDecrypt(ciphertext []byte) ([]byte, error) {
}
// EncryptWithPublicKey encrypts data with public key
func encryptWithPublicKey(msg []byte, pub *rsa.PublicKey) []byte {
func EncryptWithPublicKey(msg []byte, pub *rsa.PublicKey) []byte {
var (
hash hash.Hash
)


+ 12
- 4
Backend/Database/Sessions.go View File

@ -1,12 +1,13 @@
package Database
import (
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Models"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Models"
"gorm.io/gorm/clause"
)
func GetSessionById(id string) (Models.Session, error) {
// GetSessionByID Gets session
func GetSessionByID(id string) (Models.Session, error) {
var (
session Models.Session
err error
@ -19,6 +20,7 @@ func GetSessionById(id string) (Models.Session, error) {
return session, err
}
// CreateSession creates session
func CreateSession(session *Models.Session) error {
var (
err error
@ -29,10 +31,16 @@ func CreateSession(session *Models.Session) error {
return err
}
// DeleteSession deletes session
func DeleteSession(session *Models.Session) error {
return DB.Delete(session).Error
}
func DeleteSessionById(id string) error {
return DB.Delete(&Models.Session{}, id).Error
// DeleteSessionByID deletes session
func DeleteSessionByID(id string) error {
return DB.Delete(
&Models.Session{},
"id = ?",
id,
).Error
}

+ 1
- 1
Backend/Database/UserConversations.go View File

@ -1,7 +1,7 @@
package Database
import (
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Models"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Models"
"gorm.io/gorm"
"gorm.io/gorm/clause"


+ 1
- 1
Backend/Database/Users.go View File

@ -3,7 +3,7 @@ package Database
import (
"errors"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Models"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Models"
"gorm.io/gorm"
"gorm.io/gorm/clause"


+ 16
- 0
Backend/Dockerfile View File

@ -0,0 +1,16 @@
FROM golang:1.19-alpine
RUN mkdir -p /go/src/git.tovijaeschke.xyz/Capsule/Backend
COPY ./ /go/src/git.tovijaeschke.xyz/Capsule/Backend
WORKDIR /go/src/git.tovijaeschke.xyz/Capsule/Backend
# For "go test"
RUN apk add gcc libc-dev
RUN go mod download
RUN go build -o /go/bin/capsule-server main.go
CMD [ "/go/bin/capsule-server" ]

+ 2
- 2
Backend/Util/UserHelper.go View File

@ -5,8 +5,8 @@ import (
"log"
"net/http"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Database"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Models"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Database"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Models"
"github.com/gorilla/mux"
)


+ 1
- 1
Backend/go.mod View File

@ -1,4 +1,4 @@
module git.tovijaeschke.xyz/tovi/Envelope/Backend
module git.tovijaeschke.xyz/tovi/Capsule/Backend
go 1.18


+ 3
- 3
Backend/main.go View File

@ -5,9 +5,9 @@ import (
"log"
"net/http"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Api"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Database"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Database/Seeder"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Api"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Database"
"git.tovijaeschke.xyz/tovi/Capsule/Backend/Database/Seeder"
"github.com/gorilla/mux"
)


+ 1
- 1
README.md View File

@ -1,4 +1,4 @@
# Envelope
# Capsule
Encrypted messaging app


+ 49
- 0
docker-compose.yml View File

@ -0,0 +1,49 @@
version: "3"
services:
server:
build:
context: ./Backend
ports:
- "8080:8080"
volumes:
- "./Backend:/app"
links:
- postgres
- postgres-testing
depends_on:
postgres:
condition: service_healthy
depends_on:
postgres-testing:
condition: service_healthy
postgres:
image: postgres:14.5
ports:
- "54321:5432"
environment:
POSTGRES_DB: capsule
POSTGRES_PASSWORD: password
volumes:
- /var/lib/postgres
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
timeout: 5s
retries: 5
postgres-testing:
image: postgres:14.5
ports:
- "54322:5432"
environment:
POSTGRES_DB: capsule-testing
POSTGRES_PASSWORD: password
tmpfs:
- /var/lib/mysql
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
timeout: 5s
retries: 5

+ 1
- 1
mobile/android/app/src/main/AndroidManifest.xml View File

@ -2,7 +2,7 @@
package="com.example.mobile">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:label="Envelope"
android:label="Capsule"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
<activity


+ 2
- 2
mobile/lib/components/view_image.dart View File

@ -1,5 +1,5 @@
import 'package:Envelope/components/custom_title_bar.dart';
import 'package:Envelope/models/image_message.dart';
import 'package:Capsule/components/custom_title_bar.dart';
import 'package:Capsule/models/image_message.dart';
import 'package:flutter/material.dart';
class ViewImage extends StatelessWidget {


+ 1
- 1
mobile/lib/main.dart View File

@ -13,7 +13,7 @@ void main() async {
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
static const String _title = 'Envelope';
static const String _title = 'Capsule';
@override
Widget build(BuildContext context) {


+ 2
- 2
mobile/lib/models/conversation_users.dart View File

@ -1,8 +1,8 @@
import 'dart:convert';
import 'dart:typed_data';
import 'package:Envelope/utils/encryption/aes_helper.dart';
import 'package:Envelope/utils/encryption/crypto_utils.dart';
import 'package:Capsule/utils/encryption/aes_helper.dart';
import 'package:Capsule/utils/encryption/crypto_utils.dart';
import 'package:pointycastle/impl.dart';
import '/models/conversations.dart';


+ 2
- 2
mobile/lib/models/conversations.dart View File

@ -2,8 +2,8 @@ import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';
import 'package:Envelope/models/messages.dart';
import 'package:Envelope/models/text_messages.dart';
import 'package:Capsule/models/messages.dart';
import 'package:Capsule/models/text_messages.dart';
import 'package:mime/mime.dart';
import 'package:pointycastle/export.dart';
import 'package:sqflite/sqflite.dart';


+ 3
- 3
mobile/lib/models/image_message.dart View File

@ -2,9 +2,9 @@ import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';
import 'package:Envelope/models/my_profile.dart';
import 'package:Envelope/utils/storage/get_file.dart';
import 'package:Envelope/utils/storage/write_file.dart';
import 'package:Capsule/models/my_profile.dart';
import 'package:Capsule/utils/storage/get_file.dart';
import 'package:Capsule/utils/storage/write_file.dart';
import 'package:mime/mime.dart';
import 'package:pointycastle/pointycastle.dart';
import 'package:uuid/uuid.dart';


+ 1
- 1
mobile/lib/models/my_profile.dart View File

@ -1,7 +1,7 @@
import 'dart:convert';
import 'dart:io';
import 'package:Envelope/utils/storage/get_file.dart';
import 'package:Capsule/utils/storage/get_file.dart';
import 'package:flutter/material.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:pointycastle/impl.dart';


+ 2
- 2
mobile/lib/utils/storage/conversations.dart View File

@ -1,7 +1,7 @@
import 'dart:convert';
import 'package:Envelope/exceptions/update_data_exception.dart';
import 'package:Envelope/utils/storage/get_file.dart';
import 'package:Capsule/exceptions/update_data_exception.dart';
import 'package:Capsule/utils/storage/get_file.dart';
import 'package:flutter/material.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:http/http.dart' as http;


+ 2
- 2
mobile/lib/utils/storage/database.dart View File

@ -4,14 +4,14 @@ import 'package:path/path.dart';
import 'package:sqflite/sqflite.dart';
Future<void> deleteDb() async {
final path = join(await getDatabasesPath(), 'envelope.db');
final path = join(await getDatabasesPath(), 'capsule.db');
deleteDatabase(path);
}
Future<Database> getDatabaseConnection() async {
WidgetsFlutterBinding.ensureInitialized();
final path = join(await getDatabasesPath(), 'envelope.db');
final path = join(await getDatabasesPath(), 'capsule.db');
final database = openDatabase(
path,


+ 2
- 2
mobile/lib/utils/storage/messages.dart View File

@ -1,8 +1,8 @@
import 'dart:convert';
import 'dart:io';
import 'package:Envelope/models/messages.dart';
import 'package:Envelope/utils/storage/write_file.dart';
import 'package:Capsule/models/messages.dart';
import 'package:Capsule/utils/storage/write_file.dart';
import 'package:http/http.dart' as http;
import 'package:sqflite/sqflite.dart';
import 'package:uuid/uuid.dart';


+ 1
- 1
mobile/lib/views/authentication/login.dart View File

@ -177,7 +177,7 @@ class _LoginWidgetState extends State<LoginWidget> {
}).catchError((error) {
print(error);
showMessage(
'Could not login to Envelope, please try again later.',
'Could not login to Capsule, please try again later.',
context,
);
});


+ 3
- 3
mobile/lib/views/authentication/signup.dart View File

@ -1,8 +1,8 @@
import 'dart:convert';
import 'dart:typed_data';
import 'package:Envelope/components/flash_message.dart';
import 'package:Envelope/models/my_profile.dart';
import 'package:Capsule/components/flash_message.dart';
import 'package:Capsule/models/my_profile.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
@ -176,7 +176,7 @@ class _SignupWidgetState extends State<SignupWidget> {
.then((dynamic) {
Navigator.of(context).popUntil((route) => route.isFirst);
}).catchError((error) {
showMessage('Failed to signup to Envelope, please try again later', context);
showMessage('Failed to signup to Capsule, please try again later', context);
});
},
child: const Text('Submit'),


+ 1
- 1
mobile/lib/views/authentication/unauthenticated_landing.dart View File

@ -46,7 +46,7 @@ class _UnauthenticatedLandingWidgetState extends State<UnauthenticatedLandingWid
),
const SizedBox(width: 15),
Text(
'Envelope',
'Capsule',
style: TextStyle(
fontSize: 40,
color: Theme.of(context).colorScheme.onBackground,


+ 2
- 2
mobile/lib/views/main/conversation/create_add_users_list.dart View File

@ -1,5 +1,5 @@
import 'package:Envelope/components/custom_circle_avatar.dart';
import 'package:Envelope/models/friends.dart';
import 'package:Capsule/components/custom_circle_avatar.dart';
import 'package:Capsule/models/friends.dart';
import 'package:flutter/material.dart';
class ConversationAddFriendItem extends StatefulWidget{


+ 1
- 1
mobile/lib/views/main/conversation/detail.dart View File

@ -1,6 +1,6 @@
import 'dart:io';
import 'package:Envelope/views/main/conversation/message.dart';
import 'package:Capsule/views/main/conversation/message.dart';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';


+ 1
- 1
mobile/lib/views/main/conversation/edit_details.dart View File

@ -1,6 +1,6 @@
import 'dart:io';
import 'package:Envelope/components/file_picker.dart';
import 'package:Capsule/components/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';


+ 3
- 3
mobile/lib/views/main/conversation/list.dart View File

@ -1,8 +1,8 @@
import 'dart:io';
import 'package:Envelope/components/custom_title_bar.dart';
import 'package:Envelope/models/friends.dart';
import 'package:Envelope/utils/storage/conversations.dart';
import 'package:Capsule/components/custom_title_bar.dart';
import 'package:Capsule/models/friends.dart';
import 'package:Capsule/utils/storage/conversations.dart';
import 'package:flutter/material.dart';
import '/models/conversations.dart';


+ 4
- 4
mobile/lib/views/main/conversation/message.dart View File

@ -1,7 +1,7 @@
import 'package:Envelope/components/view_image.dart';
import 'package:Envelope/models/image_message.dart';
import 'package:Envelope/models/my_profile.dart';
import 'package:Envelope/utils/time.dart';
import 'package:Capsule/components/view_image.dart';
import 'package:Capsule/models/image_message.dart';
import 'package:Capsule/models/my_profile.dart';
import 'package:Capsule/utils/time.dart';
import 'package:flutter/material.dart';
import '/models/messages.dart';


+ 7
- 7
mobile/lib/views/main/conversation/settings.dart View File

@ -1,12 +1,12 @@
import 'dart:io';
import 'package:Envelope/components/custom_title_bar.dart';
import 'package:Envelope/components/flash_message.dart';
import 'package:Envelope/exceptions/update_data_exception.dart';
import 'package:Envelope/models/friends.dart';
import 'package:Envelope/utils/encryption/crypto_utils.dart';
import 'package:Envelope/utils/storage/write_file.dart';
import 'package:Envelope/views/main/conversation/create_add_users.dart';
import 'package:Capsule/components/custom_title_bar.dart';
import 'package:Capsule/components/flash_message.dart';
import 'package:Capsule/exceptions/update_data_exception.dart';
import 'package:Capsule/models/friends.dart';
import 'package:Capsule/utils/encryption/crypto_utils.dart';
import 'package:Capsule/utils/storage/write_file.dart';
import 'package:Capsule/views/main/conversation/create_add_users.dart';
import 'package:flutter/material.dart';
import '/models/conversation_users.dart';


+ 4
- 4
mobile/lib/views/main/friend/list.dart View File

@ -1,7 +1,7 @@
import 'package:Envelope/components/custom_title_bar.dart';
import 'package:Envelope/components/qr_reader.dart';
import 'package:Envelope/views/main/friend/add_search.dart';
import 'package:Envelope/views/main/friend/request_list_item.dart';
import 'package:Capsule/components/custom_title_bar.dart';
import 'package:Capsule/components/qr_reader.dart';
import 'package:Capsule/views/main/friend/add_search.dart';
import 'package:Capsule/views/main/friend/request_list_item.dart';
import 'package:flutter/material.dart';
import '/models/friends.dart';


+ 6
- 6
mobile/lib/views/main/friend/list_item.dart View File

@ -1,9 +1,9 @@
import 'package:Envelope/components/custom_circle_avatar.dart';
import 'package:Envelope/models/conversations.dart';
import 'package:Envelope/models/friends.dart';
import 'package:Envelope/utils/storage/conversations.dart';
import 'package:Envelope/utils/strings.dart';
import 'package:Envelope/views/main/conversation/detail.dart';
import 'package:Capsule/components/custom_circle_avatar.dart';
import 'package:Capsule/models/conversations.dart';
import 'package:Capsule/models/friends.dart';
import 'package:Capsule/utils/storage/conversations.dart';
import 'package:Capsule/utils/strings.dart';
import 'package:Capsule/views/main/conversation/detail.dart';
import 'package:flutter/material.dart';
class FriendListItem extends StatefulWidget{


+ 1
- 1
mobile/lib/views/main/profile/change_server_url.dart View File

@ -111,7 +111,7 @@ WARNING: Do not use this feature unless you know what you\'re doing!
''';
String warning2 = '''
Changing the server url will disconnect you from all friends and conversations on this server, and connect you to a fresh environment. This feature is intended to be used by people that are willing to host their own Envelope server, which you can find by going to \nhttps://github.com/SomeUsername/SomeRepo.\n\n
Changing the server url will disconnect you from all friends and conversations on this server, and connect you to a fresh environment. This feature is intended to be used by people that are willing to host their own Capsule server, which you can find by going to \nhttps://github.com/SomeUsername/SomeRepo.\n\n
You can revert this by entering \nhttps://envelope-messenger.com\n on the login screen.
''';


+ 5
- 5
mobile/lib/views/main/profile/profile.dart View File

@ -2,11 +2,11 @@ import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';
import 'package:Envelope/components/file_picker.dart';
import 'package:Envelope/components/flash_message.dart';
import 'package:Envelope/utils/encryption/aes_helper.dart';
import 'package:Envelope/utils/storage/session_cookie.dart';
import 'package:Envelope/utils/storage/write_file.dart';
import 'package:Capsule/components/file_picker.dart';
import 'package:Capsule/components/flash_message.dart';
import 'package:Capsule/utils/encryption/aes_helper.dart';
import 'package:Capsule/utils/storage/session_cookie.dart';
import 'package:Capsule/utils/storage/write_file.dart';
import 'package:flutter/material.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:image_picker/image_picker.dart';


+ 2
- 2
mobile/pubspec.yaml View File

@ -1,5 +1,5 @@
name: Envelope
description: A new Flutter project.
name: Capsule
description: An encrypted messaging app
publish_to: 'none' # Remove this line if you wish to publish to pub.dev


+ 3
- 0
test.sh View File

@ -0,0 +1,3 @@
#!/bin/sh
docker-compose exec server sh -c "cd /app && go test -v ./Api/Auth"

Loading…
Cancel
Save