Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SRE-3199: Sync with upstream and release new image version #5

Merged
merged 8 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading