Skip to content

Commit

Permalink
upgrade to github.com/greenpau/go-authcrunch v1.0.10
Browse files Browse the repository at this point in the history
  • Loading branch information
greenpau committed Jan 29, 2022
1 parent ab4dab5 commit c39eee2
Show file tree
Hide file tree
Showing 14 changed files with 336 additions and 131 deletions.
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ module github.com/greenpau/caddy-security
go 1.16
require (
github.com/greenpau/go-authcrunch v1.0.5
github.com/greenpau/go-authcrunch v1.0.10
)
replace github.com/greenpau/go-authcrunch v1.0.5 => /home/greenpau/dev/go/src/github.com/greenpau/go-authcrunch
replace github.com/greenpau/go-authcrunch v1.0.10 => /home/greenpau/dev/go/src/github.com/greenpau/go-authcrunch
```

Then, modify `Makefile` such that that replacement passes to `xcaddy` builder:
Expand All @@ -93,7 +93,7 @@ Then, modify `Makefile` such that that replacement passes to `xcaddy` builder:
@mkdir -p ../xcaddy-$(PLUGIN_NAME) && cd ../xcaddy-$(PLUGIN_NAME) && \
xcaddy build $(CADDY_VERSION) --output ../$(PLUGIN_NAME)/bin/caddy \
--with github.com/greenpau/caddy-security@$(LATEST_GIT_COMMIT)=$(BUILD_DIR) \
--with github.com/greenpau/[email protected].5=/home/greenpau/dev/go/src/github.com/greenpau/go-authcrunch
--with github.com/greenpau/[email protected].10=/home/greenpau/dev/go/src/github.com/greenpau/go-authcrunch
```

Once all the necessary packages are installed, you should be ready to compile
Expand Down
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ all: info
@mkdir -p ../xcaddy-$(PLUGIN_NAME) && cd ../xcaddy-$(PLUGIN_NAME) && \
xcaddy build $(CADDY_VERSION) --output ../$(PLUGIN_NAME)/bin/caddy \
--with github.com/greenpau/caddy-security@$(LATEST_GIT_COMMIT)=$(BUILD_DIR)
@#--with github.com/greenpau/[email protected].9=/home/greenpau/dev/go/src/github.com/greenpau/go-authcrunch
@#--with github.com/greenpau/[email protected].10=/home/greenpau/dev/go/src/github.com/greenpau/go-authcrunch
@#--with github.com/greenpau/[email protected]=/home/greenpau/dev/go/src/github.com/greenpau/caddy-trace
@#bin/caddy run -config assets/config/Caddyfile
@for f in `find ./assets -type f -name 'Caddyfile'`; do bin/caddy fmt -overwrite $$f; done
Expand Down Expand Up @@ -69,8 +69,9 @@ qtest: covdir
@#time richgo test -v -coverprofile=.coverage/coverage.out -run TestApp ./*.go
@#time richgo test -v -coverprofile=.coverage/coverage.out -run TestParseCaddyfileAppConfig ./*.go
@#time richgo test -v -coverprofile=.coverage/coverage.out -run TestParseCaddyfileCredentials ./*.go
@time richgo test -v -coverprofile=.coverage/coverage.out -run TestParseCaddyfileMessaging ./*.go
@#time richgo test -v -coverprofile=.coverage/coverage.out -run TestParseCaddyfileAuthentication ./*.go
@time richgo test -v -coverprofile=.coverage/coverage.out -run TestParseCaddyfileAuthorization ./*.go
@#time richgo test -v -coverprofile=.coverage/coverage.out -run TestParseCaddyfileAuthorization ./*.go
@#go test -v -coverprofile=.coverage/coverage.out -run TestParseCaddyfile ./*.go
@#go test -v -coverprofile=.coverage/coverage.out -run Test* ./pkg/services/...
@go tool cover -html=.coverage/coverage.out -o .coverage/coverage.html
Expand Down
25 changes: 21 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Please see other plugins:
* [Overview](#overview)
* [Getting Started](#getting-started)
* [Credentials](#credentials)
* [Messaging](#messaging)
* [Authentication](#authentication)
* [Authorization](#authorization)
* [User Interface](#user-interface)
Expand Down Expand Up @@ -82,21 +83,37 @@ Download Caddy with the plugins enabled:
### Credentials

The following configuration adds SMTP credentials to security app.
Subsequently, the app and plugin will be able to use the credentials.
Subsequently, the app and plugin will be able to use the credentials
in its messaging configuration.

```
{
security {
credentials email smtp.outlook.com {
address outlook.office365.com:993
protocol smtp
credentials smtp.outlook.com {
username {env.SMTP_USERNAME}
password {env.SMTP_PASSWORD}
}
}
}
```

### Messaging

The following configuration sets up email messaging provider. It will use
the previously configured `smtp.outlook.com` credentials.

```
{
security {
messaging email provider smtp.outlook.com {
address outlook.office365.com:25
protocol smtp
credentials smtp.outlook.com
}
}
}
```

### Authentication

The following configuration adds authentication portal.
Expand Down
5 changes: 2 additions & 3 deletions assets/config/Caddyfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
https_port 8443

security {
credentials email smtp.contoso.com {
address smtp.contoso.com:993
protocol smtp
credentials smtp.contoso.com {
username foo
password bar
domain contoso.com
}

authentication portal myportal {
Expand Down
57 changes: 0 additions & 57 deletions assets/config/jumpcloud/Caddyfile

This file was deleted.

12 changes: 12 additions & 0 deletions assets/scripts/update_doc_refs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
set -e

printf "Updating doc references\n"

ACV=`cat ../go-authcrunch/VERSION | head -1`
echo "go-authcrunch v${ACV}"

sed -i 's/go-authcrunch v[0-9]\.[0-9]*\.[0-9]*/go-authcrunch v'"${ACV}"'/' CONTRIBUTING.md
sed -i 's/go-authcrunch@v[0-9]\.[0-9]*\.[0-9]*/go-authcrunch@v'"${ACV}"'/' CONTRIBUTING.md
sed -i 's/go-authcrunch@v[0-9]\.[0-9]*\.[0-9]*/go-authcrunch@v'"${ACV}"'/' Makefile
sed -i 's/go-authcrunch v[0-9]\.[0-9]*\.[0-9]*/go-authcrunch v'"${ACV}"'/' go.mod
4 changes: 4 additions & 0 deletions caddyfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ func parseCaddyfile(d *caddyfile.Dispenser, _ interface{}) (interface{}, error)
if err := parseCaddyfileCredentials(d, repl, app.Config); err != nil {
return nil, err
}
case "messaging":
if err := parseCaddyfileMessaging(d, repl, app.Config); err != nil {
return nil, err
}
case "authentication":
if err := parseCaddyfileAuthentication(d, repl, app.Config); err != nil {
return nil, err
Expand Down
46 changes: 19 additions & 27 deletions caddyfile_credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,42 +31,34 @@ const (
//
// Syntax:
//
// credentials email <label> {
// address <uri>
// protocol <smtp|pop3|imap>
// credentials <label> {
// username <username>
// password <password>
// domain <name>
// }
//
func parseCaddyfileCredentials(d *caddyfile.Dispenser, repl *caddy.Replacer, cfg *authcrunch.Config) error {
args := util.FindReplaceAll(repl, d.RemainingArgs())
if len(args) != 2 {
if len(args) != 1 {
return d.ArgErr()
}
switch args[0] {
case "email":
c := &credentials.SMTP{Name: args[1]}
for nesting := d.Nesting(); d.NextBlock(nesting); {
k := d.Val()
v := util.FindReplaceAll(repl, d.RemainingArgs())
switch k {
case "address":
c.Address = v[0]
case "protocol":
c.Protocol = v[0]
case "username":
c.Username = v[0]
case "password":
c.Password = v[0]
default:
return errors.ErrMalformedDirective.WithArgs([]string{credPrefix, args[0], k}, v)
}
c := &credentials.Generic{Name: args[0]}
for nesting := d.Nesting(); d.NextBlock(nesting); {
k := d.Val()
v := util.FindReplaceAll(repl, d.RemainingArgs())
switch k {
case "domain":
c.Domain = v[0]
case "username":
c.Username = v[0]
case "password":
c.Password = v[0]
default:
return errors.ErrMalformedDirective.WithArgs([]string{credPrefix, args[0], k}, v)
}
if err := cfg.AddCredential(c); err != nil {
return errors.ErrMalformedDirective.WithArgs([]string{credPrefix, args[0], args[1]}, err)
}
default:
return errors.ErrMalformedDirective.WithArgs(credPrefix, args)
}
if err := cfg.AddCredential(c); err != nil {
return errors.ErrMalformedDirective.WithArgs([]string{credPrefix, args[0]}, err)
}
return nil
}
67 changes: 42 additions & 25 deletions caddyfile_credentials_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,85 +36,102 @@ func TestParseCaddyfileCredentials(t *testing.T) {
name: "test valid smtp credentials",
d: caddyfile.NewTestDispenser(`
security {
credentials email smtp.contoso.com {
address smtp.contoso.com:993
protocol smtp
username foo
password bar
credentials smtp.contoso.com {
username foo
password bar
}
}`),
want: `{
"config": {
"credentials": {
"email": [
"generic": [
{
"address": "smtp.contoso.com:993",
"name": "smtp.contoso.com",
"username": "foo",
"password": "bar",
"protocol": "smtp"
"password": "bar"
}
]
}
}
}`,
},
{
name: "test valid smtp credentials with optional domain",
d: caddyfile.NewTestDispenser(`
security {
credentials smtp.contoso.com {
username foo
password bar
domain contoso.com
}
}`),
want: `{
"config": {
"credentials": {
"generic": [
{
"name": "smtp.contoso.com",
"username": "foo",
"password": "bar",
"domain": "contoso.com"
}
]
}
}
}`,
},
{
name: "test malformed credentials definition",
d: caddyfile.NewTestDispenser(`
security {
credentials email smtp.contoso.com foo {
credentials smtp.contoso.com foo {
username foo
password bar
}
}`),
shouldErr: true,
err: fmt.Errorf("%s:%d - Error during parsing: Wrong argument count or unexpected line ending after '%s'", tf, 3, "foo"),
err: fmt.Errorf("%s:%d - Error during parsing: Wrong argument count or unexpected line ending after 'foo'", tf, 3),
},
{
name: "test unsupported credentials keyword",
d: caddyfile.NewTestDispenser(`
security {
credentials email smtp.contoso.com {
credentials smtp.contoso.com {
foo bar
}
}`),
shouldErr: true,
err: errors.ErrMalformedDirective.WithArgs(
[]string{credPrefix, "email", "foo"},
[]string{credPrefix, "smtp.contoso.com", "foo"},
[]string{"bar"},
),
},
{
name: "test smtp credentials without address",
name: "test smtp credentials without username",
d: caddyfile.NewTestDispenser(`
security {
credentials email smtp.contoso.com {
protocol smtp
username foo
credentials smtp.contoso.com {
password bar
}
}`),
shouldErr: true,
err: errors.ErrMalformedDirective.WithArgs(
[]string{credPrefix, "email", "smtp.contoso.com"},
errors.ErrCredKeyValueEmpty.WithArgs("address"),
[]string{credPrefix, "smtp.contoso.com"},
errors.ErrCredKeyValueEmpty.WithArgs("username"),
),
},
{
name: "test unsupported credentials type",
name: "test smtp credentials without password",
d: caddyfile.NewTestDispenser(`
security {
credentials foo bar {
protocol smtp
credentials smtp.contoso.com {
username foo
password bar
}
}`),
shouldErr: true,
err: errors.ErrMalformedDirective.WithArgs(
credPrefix,
[]string{"foo", "bar"},
[]string{credPrefix, "smtp.contoso.com"},
errors.ErrCredKeyValueEmpty.WithArgs("password"),
),
},
}
Expand Down
Loading

0 comments on commit c39eee2

Please sign in to comment.