Skip to content

Commit

Permalink
Merge pull request #5 from EQTPartners/SRE-3199_sync_fork_with_upstream
Browse files Browse the repository at this point in the history
SRE-3199: Sync with upstream and release new image version
  • Loading branch information
tlinderdahl-eqt authored Feb 14, 2024
2 parents 2d52b8e + e9b62e2 commit d0d1608
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 16 deletions.
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ commands:
- run:
name: Build and push application container image
command: |
serverImageTag="eu.gcr.io/<< parameters.imageProjectId >>/${APP_NAME}-image:<< parameters.tagNumber >>"
serverImageTag="europe-west1-docker.pkg.dev/<< parameters.imageProjectId >>/${APP_NAME}-repository/${APP_NAME}-image:<< parameters.tagNumber >>"
docker build -t ${serverImageTag} --file Dockerfile .
docker push ${serverImageTag}
Expand All @@ -49,8 +49,8 @@ jobs:
executor: gcp
steps:
- build_and_push_image:
imageProjectId: "eqt-i9n-infra-test"
tagNumber: "4"
imageProjectId: "eqt-cicd-prod"
tagNumber: "5"

workflows:
version: 2.1
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ FROM debian:stable-slim
RUN useradd -m -d /opt/gophish -s /bin/bash app

RUN apt-get update && \
apt-get install --no-install-recommends -y jq libcap2-bin && \
apt-get install --no-install-recommends -y jq libcap2-bin ca-certificates && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

Expand Down
8 changes: 8 additions & 0 deletions docker/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ if [ -n "${CONTACT_ADDRESS+set}" ] ; then
cat config.json.tmp > config.json
fi

# db_name has to be changed to mysql for mysql connection to work
if [ -n "${DB_NAME+set}" ] ; then
jq -r \
--arg DB_NAME "${DB_NAME}" \
'.db_name = $DB_NAME' config.json > config.json.tmp && \
cat config.json.tmp > config.json
fi

if [ -n "${DB_FILE_PATH+set}" ] ; then
jq -r \
--arg DB_FILE_PATH "${DB_FILE_PATH}" \
Expand Down
2 changes: 1 addition & 1 deletion models/maillog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ func (s *ModelsSuite) TestMailLogGenerateOverrideTransparencyHeaders(ch *check.C
smtp := SMTP{
Name: "Test SMTP",
Host: "1.1.1.1:25",
FromAddress: "Foo Bar <[email protected]>",
FromAddress: "[email protected]",
UserId: 1,
Headers: []Header{
Header{Key: "X-Gophish-Contact", Value: ""},
Expand Down
13 changes: 13 additions & 0 deletions models/smtp.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"net/mail"
"os"
"regexp"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -57,6 +58,10 @@ type Header struct {
// specified in the SMTP configuration
var ErrFromAddressNotSpecified = errors.New("No From Address specified")

// ErrInvalidFromAddress is thrown when the SMTP From field in the sending
// profiles containes a value that is not an email address
var ErrInvalidFromAddress = errors.New("Invalid SMTP From address because it is not an email address")

// ErrHostNotSpecified is thrown when there is no Host specified
// in the SMTP configuration
var ErrHostNotSpecified = errors.New("No SMTP Host specified")
Expand All @@ -76,6 +81,8 @@ func (s *SMTP) Validate() error {
return ErrFromAddressNotSpecified
case s.Host == "":
return ErrHostNotSpecified
case !validateFromAddress(s.FromAddress):
return ErrInvalidFromAddress
}
_, err := mail.ParseAddress(s.FromAddress)
if err != nil {
Expand All @@ -95,6 +102,12 @@ func (s *SMTP) Validate() error {
return err
}

// validateFromAddress validates
func validateFromAddress(email string) bool {
r, _ := regexp.Compile("^([a-zA-Z0-9_\\-\\.]+)@([a-zA-Z0-9_\\-\\.]+)\\.([a-zA-Z]{2,18})$")
return r.MatchString(email)
}

// GetDialer returns a dialer for the given SMTP profile
func (s *SMTP) GetDialer() (mailer.Dialer, error) {
// Setup the message and dial
Expand Down
28 changes: 25 additions & 3 deletions models/smtp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func (s *ModelsSuite) TestPostSMTP(c *check.C) {
smtp := SMTP{
Name: "Test SMTP",
Host: "1.1.1.1:25",
FromAddress: "Foo Bar <[email protected]>",
FromAddress: "[email protected]",
UserId: 1,
}
err := PostSMTP(&smtp)
Expand All @@ -25,7 +25,7 @@ func (s *ModelsSuite) TestPostSMTP(c *check.C) {
func (s *ModelsSuite) TestPostSMTPNoHost(c *check.C) {
smtp := SMTP{
Name: "Test SMTP",
FromAddress: "Foo Bar <[email protected]>",
FromAddress: "[email protected]",
UserId: 1,
}
err := PostSMTP(&smtp)
Expand All @@ -42,12 +42,34 @@ func (s *ModelsSuite) TestPostSMTPNoFrom(c *check.C) {
c.Assert(err, check.Equals, ErrFromAddressNotSpecified)
}

func (s *ModelsSuite) TestPostSMTPValidHeader(c *check.C) {
func (s *ModelsSuite) TestPostInvalidFrom(c *check.C) {
smtp := SMTP{
Name: "Test SMTP",
Host: "1.1.1.1:25",
FromAddress: "Foo Bar <[email protected]>",
UserId: 1,
}
err := PostSMTP(&smtp)
c.Assert(err, check.Equals, ErrInvalidFromAddress)
}

func (s *ModelsSuite) TestPostInvalidFromEmail(c *check.C) {
smtp := SMTP{
Name: "Test SMTP",
Host: "1.1.1.1:25",
FromAddress: "example.com",
UserId: 1,
}
err := PostSMTP(&smtp)
c.Assert(err, check.Equals, ErrInvalidFromAddress)
}

func (s *ModelsSuite) TestPostSMTPValidHeader(c *check.C) {
smtp := SMTP{
Name: "Test SMTP",
Host: "1.1.1.1:25",
FromAddress: "[email protected]",
UserId: 1,
Headers: []Header{
Header{Key: "Reply-To", Value: "[email protected]"},
Header{Key: "X-Mailer", Value: "gophish"},
Expand Down
Loading

0 comments on commit d0d1608

Please sign in to comment.