Repository: prest/prest
Pull request #696 (2022-04-18 09:06:44)

Bump github.com/jmoiron/sqlx from 1.3.4 to 1.3.5
Bumps [github.com/jmoiron/sqlx](https://github.com/jmoiron/sqlx) from 1.3.4 to 1.3.5.
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/jmoiron/sqlx/commit/28212d434cdd87418ecd0cb81173690ce7ac6ab6"><code>28212d4</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/jmoiron/sqlx/issues/767">#767</a> from liftoffio/gpark.sqlx.reset-slice</li>
<li><a href="https://github.com/jmoiron/sqlx/commit/421d1cdb91272811eee9c2cdcdf4ff4b40568ef8"><code>421d1cd</code></a> Make Select reset slice length</li>
<li><a href="https://github.com/jmoiron/sqlx/commit/a62bc6088664eb854c3d5ebbd08a1ffd59662ef1"><code>a62bc60</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/jmoiron/sqlx/issues/728">#728</a> from s7v7nislands/update_mysql_version</li>
<li><a href="https://github.com/jmoiron/sqlx/commit/2765bc4e5cbe06ce71494ba50627a2d3828ef07c"><code>2765bc4</code></a> update go-sql-driver/mysql to v1.6.0</li>
<li>See full diff in <a href="https://github.com/jmoiron/sqlx/compare/v1.3.4...v1.3.5">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=github.com/jmoiron/sqlx&package-manager=go_modules&previous-version=1.3.4&new-version=1.3.5)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>

pull-request-quantifier[bot]: ### ![](https://img.shields.io/static/v1?label=Quantified&message=Extra%20Small&color=green)

This PR has `10` quantified lines of changes. In general, a change size of upto `200` lines is ideal for the best PR experience!

------

<details >
    <summary display="inline"> <strong>Quantification details</strong></summary>
    <p />

```
Label      : Extra Small
Size       : +5 -5
Percentile : 4%

Total files changed: 2

Change summary by file extension:
.mod : +1 -1
.sum : +4 -4
```
> Change counts above are quantified counts, based on the [PullRequestQuantifier customizations](https://github.com/microsoft/PullRequestQuantifier/blob/main/docs/prquantifier-yaml.md).
    
</details>


<details>
    <summary display="inline"> <strong>Why proper sizing of changes matters</strong> </summary>
    <p/>
    <p/>

Optimal pull request sizes drive a better predictable PR flow as they strike a
balance between between PR complexity and PR review overhead. PRs within the
optimal size (typical small, or medium sized PRs) mean:

- Fast and predictable releases to production:
  - Optimal size changes are more likely to be reviewed faster with fewer
iterations.
  - Similarity in low PR complexity drives similar review times.
- Review quality is likely higher as complexity is lower:
  - Bugs are more likely to be detected.
  - Code inconsistencies are more likely to be detetcted.
- Knowledge sharing is improved within the participants:
  - Small portions can be assimilated better.
- Better engineering practices are exercised:
  - Solving big problems by dividing them in well contained, smaller problems.
  - Exercising separation of concerns within the code changes.

#### What can I do to optimize my changes

- Use the PullRequestQuantifier to quantify your PR accurately
  - Create a context profile for your repo using the [context generator](https://github.com/microsoft/PullRequestQuantifier/releases)
  - Exclude files that are not necessary to be reviewed or do not increase the review complexity. Example: Autogenerated code, docs, project IDE setting files, binaries, etc. Check out the `Excluded` section from your `prquantifier.yaml` context profile. 
  - Understand your typical change complexity, drive towards the desired complexity by adjusting the label mapping in your `prquantifier.yaml` context profile.
  - Only use the labels that matter to you, [see context specification](./docs/prquantifier-yaml.md) to customize your `prquantifier.yaml` context profile.
- Change your engineering behaviors
  - For PRs that fall outside of the desired spectrum, review the details and check if:
    - Your PR could be split in smaller, self-contained PRs instead
    - Your PR only solves one particular issue. (For example, don't refactor and code new features in the same PR).

#### How to interpret the change counts in git diff output

- One line was added: `+1 -0`
- One line was deleted: `+0 -1`
- One line was modified: `+1 -1` (git diff doesn't know about modified, it will
interpret that line like one addition plus one deletion)
- Change percentiles: Change characteristics (addition, deletion, modification)
of this PR in relation to all other PRs within the repository.

</details>

<p />

------

Was this comment helpful? <a href="https://pullrequestquantifierfeedback.azurewebsites.net/feedback?payload=eyJBdXRob3JOYW1lIjoiZGVwZW5kYWJvdFtib3RdIiwiUmVwb3NpdG9yeUxpbmsiOiJodHRwczovL2dpdGh1Yi5jb20vcHJlc3QvcHJlc3QiLCJQdWxsUmVxdWVzdExpbmsiOiJodHRwczovL2dpdGh1Yi5jb20vcHJlc3QvcHJlc3QvcHVsbC82OTYiLCJFdmVudFR5cGUiOiJUaHVtYnNVcCJ9&amp;anonymous=True" target="_blank" title="Thumbs up"><strong>:thumbsup:</strong></a> <a href="https://pullrequestquantifierfeedback.azurewebsites.net/feedback?payload=eyJBdXRob3JOYW1lIjoiZGVwZW5kYWJvdFtib3RdIiwiUmVwb3NpdG9yeUxpbmsiOiJodHRwczovL2dpdGh1Yi5jb20vcHJlc3QvcHJlc3QiLCJQdWxsUmVxdWVzdExpbmsiOiJodHRwczovL2dpdGh1Yi5jb20vcHJlc3QvcHJlc3QvcHVsbC82OTYiLCJFdmVudFR5cGUiOiJOZXV0cmFsIn0=&amp;anonymous=True" target="_blank" title="Neutral"><strong>&nbsp;:ok_hand:</strong></a> <a href="https://pullrequestquantifierfeedback.azurewebsites.net/feedback?payload=eyJBdXRob3JOYW1lIjoiZGVwZW5kYWJvdFtib3RdIiwiUmVwb3NpdG9yeUxpbmsiOiJodHRwczovL2dpdGh1Yi5jb20vcHJlc3QvcHJlc3QiLCJQdWxsUmVxdWVzdExpbmsiOiJodHRwczovL2dpdGh1Yi5jb20vcHJlc3QvcHJlc3QvcHVsbC82OTYiLCJFdmVudFR5cGUiOiJUaHVtYnNEb3duIn0=&amp;anonymous=True" target="_blank" title="Thumbs down"><strong>&nbsp;:thumbsdown:</strong></a> (<a href="MAILTO:prquantifier@microsoft.com" title="Mail to prquantifier@microsoft.com">Email</a>)
[Customize PullRequestQuantifier](https://github.com/microsoft/PullRequestQuantifier/blob/main/docs/prquantifier-yaml.md) for this repository.


CLAassistant: [![CLA assistant check](https://cla-assistant.io/pull/badge/not_signed)](https://cla-assistant.io/prest/prest?pullRequest=696) <br/>Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our [Contributor License Agreement](https://cla-assistant.io/prest/prest?pullRequest=696) before we can accept your contribution.<br/><sub>You have signed the CLA already but the status is still pending? Let us [recheck](https://cla-assistant.io/check/prest/prest?pullRequest=696) it.</sub>
codecov[bot]: # [Codecov](https://codecov.io/gh/prest/prest/pull/696?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=prest) Report
> Merging [#696](https://codecov.io/gh/prest/prest/pull/696?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=prest) (073ca75) into [main](https://codecov.io/gh/prest/prest/commit/e46c8128446a4024636d056fb235a05edf2e11a9?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=prest) (e46c812) will **not change** coverage.
> The diff coverage is `n/a`.

```diff
@@           Coverage Diff           @@
##             main     #696   +/-   ##
=======================================
  Coverage   76.54%   76.54%           
=======================================
  Files          25       25           
  Lines        2840     2840           
=======================================
  Hits         2174     2174           
  Misses        559      559           
  Partials      107      107           
```



------

[Continue to review full report at Codecov](https://codecov.io/gh/prest/prest/pull/696?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=prest).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=prest)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/prest/prest/pull/696?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=prest). Last update [e46c812...073ca75](https://codecov.io/gh/prest/prest/pull/696?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=prest). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=prest).


Patch:
diff --git a/cmd/auth.go b/cmd/auth.go
index 0b453bf..5d910ef 100644
--- a/cmd/auth.go
+++ b/cmd/auth.go
@@ -23,7 +23,7 @@ var authUpCmd = &cobra.Command{
 			fmt.Fprintf(os.Stdout, err.Error())
 			return err
 		}
-		_, err = db.Exec("CREATE TABLE IF NOT EXISTS public.prest_users (id serial, name text, username text unique, password text, metadata jsonb)")
+		_, err = db.Exec("CREATE TABLE IF NOT EXISTS %s.%s (id serial, name text, username text unique, password text, metadata jsonb)", config.PrestConf.AuthSchema, config.PrestConf.AuthTable)
 		if err != nil {
 			fmt.Fprintf(os.Stdout, err.Error())
 			return err
@@ -46,7 +46,7 @@ var authDownCmd = &cobra.Command{
 			fmt.Fprintf(os.Stdout, err.Error())
 			return err
 		}
-		_, err = db.Exec("DROP TABLE IF EXISTS public.prest_users")
+		_, err = db.Exec("DROP TABLE IF EXISTS %s.%s", config.PrestConf.AuthSchema, config.PrestConf.AuthTable)
 		if err != nil {
 			fmt.Fprintf(os.Stdout, err.Error())
 			return err
diff --git a/config/config.go b/config/config.go
index 7336f45..1ee029c 100644
--- a/config/config.go
+++ b/config/config.go
@@ -47,6 +47,7 @@ type AccessConf struct {
 // Prest basic config
 type Prest struct {
 	AuthEnabled      bool
+	AuthSchema       string
 	AuthTable        string
 	AuthUsername     string
 	AuthPassword     string
@@ -112,6 +113,7 @@ func viperCfg() {
 	viper.SetDefault("auth.enabled", false)
 	viper.SetDefault("auth.username", "username")
 	viper.SetDefault("auth.password", "password")
+	viper.SetDefault("auth.schema", "public")
 	viper.SetDefault("auth.table", "prest_users")
 	viper.SetDefault("auth.encrypt", "MD5")
 	viper.SetDefault("auth.type", "body")
@@ -171,6 +173,7 @@ func Parse(cfg *Prest) (err error) {
 		}
 	}
 	cfg.AuthEnabled = viper.GetBool("auth.enabled")
+	cfg.AuthSchema = viper.GetString("auth.schema")
 	cfg.AuthTable = viper.GetString("auth.table")
 	cfg.AuthUsername = viper.GetString("auth.username")
 	cfg.AuthPassword = viper.GetString("auth.password")
diff --git a/controllers/auth.go b/controllers/auth.go
index 38e80ad..837ac0c 100644
--- a/controllers/auth.go
+++ b/controllers/auth.go
@@ -131,7 +131,7 @@ func basicPasswordCheck(user, password string) (obj auth.User, err error) {
 
 // getSelectQuery create the query to authenticate the user
 func getSelectQuery() (query string) {
-	query = fmt.Sprintf(`SELECT * FROM %s WHERE %s=$1 AND %s=$2 LIMIT 1`, config.PrestConf.AuthTable, config.PrestConf.AuthUsername, config.PrestConf.AuthPassword)
+	query = fmt.Sprintf(`SELECT * FROM %s.%s WHERE %s=$1 AND %s=$2 LIMIT 1`, config.PrestConf.AuthSchema, config.PrestConf.AuthTable, config.PrestConf.AuthUsername, config.PrestConf.AuthPassword)
 	return
 }
 
diff --git a/docs/deployment/server-configuration.md b/docs/deployment/server-configuration.md
index f2a7430..2951fef 100644
--- a/docs/deployment/server-configuration.md
+++ b/docs/deployment/server-configuration.md
@@ -31,6 +31,7 @@ The _**prestd**_ configuration is via an _environment variable_ or _toml_ file.
 | PREST\_AUTH_ENABLED | false | |
 | PREST\_AUTH_ENCRYPT | MD5 | |
 | PREST\_AUTH_TYPE | body | |
+| PREST\_AUTH_SCHEMA | public | |
 | PREST\_AUTH_TABLE | prest_users | |
 | PREST\_AUTH_USERNAME | username | |
 | PREST\_AUTH_PASSWORD | password | |
diff --git a/go.mod b/go.mod
index bd5fc9b..4a82a56 100644
--- a/go.mod
+++ b/go.mod
@@ -7,7 +7,7 @@ require (
 	github.com/clbanning/mxj v1.8.4
 	github.com/gorilla/mux v1.8.0
 	github.com/gosidekick/migration/v3 v3.0.0
-	github.com/jmoiron/sqlx v1.3.4
+	github.com/jmoiron/sqlx v1.3.5
 	github.com/lib/pq v1.10.5
 	github.com/mitchellh/go-homedir v1.1.0
 	github.com/spf13/cobra v1.4.0
diff --git a/go.sum b/go.sum
index 53b22ba..5e6857f 100644
--- a/go.sum
+++ b/go.sum
@@ -121,8 +121,8 @@ github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2
 github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
 github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
 github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
-github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
-github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
+github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
+github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
 github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
 github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
 github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
@@ -243,8 +243,8 @@ github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:
 github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
 github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
 github.com/jmoiron/sqlx v1.2.0/go.mod h1:1FEQNm3xlJgrMD+FBdI9+xvCksHtbpVBBw5dYhBSsks=
-github.com/jmoiron/sqlx v1.3.4 h1:wv+0IJZfL5z0uZoUjlpKgHkgaFSYD+r9CfrXjEXsO7w=
-github.com/jmoiron/sqlx v1.3.4/go.mod h1:2BljVx/86SuTyjE+aPYlHCTNvZrnJXghYGpNiXLBMCQ=
+github.com/jmoiron/sqlx v1.3.5 h1:vFFPA71p1o5gAeqtEAwLU4dnX2napprKtHr7PYIcN3g=
+github.com/jmoiron/sqlx v1.3.5/go.mod h1:nRVWtLre0KfCLJvgxzCsLVMogSvQ1zNJtpYr2Ccp0mQ=
 github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
 github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
 github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=


Test patch:
diff --git a/config/config_test.go b/config/config_test.go
index 5b49802..5a826a9 100644
--- a/config/config_test.go
+++ b/config/config_test.go
@@ -6,6 +6,7 @@ import (
 )
 
 func TestLoad(t *testing.T) {
+	os.Setenv("PREST_CONF", "../testdata/prest.toml")
 	Load()
 	if len(PrestConf.AccessConf.Tables) < 2 {
 		t.Errorf("expected > 2, got: %d", len(PrestConf.AccessConf.Tables))
@@ -28,6 +29,7 @@ func TestLoad(t *testing.T) {
 }
 
 func TestParse(t *testing.T) {
+	os.Setenv("PREST_CONF", "../testdata/prest.toml")
 	viperCfg()
 	cfg := &Prest{}
 	err := Parse(cfg)
@@ -37,11 +39,18 @@ func TestParse(t *testing.T) {
 	if cfg.HTTPPort != 6000 {
 		t.Errorf("expected port: 6000, got: %d", cfg.HTTPPort)
 	}
-	if cfg.PGDatabase != "prest-test" {
-		t.Errorf("expected database: prest, got: %s", cfg.PGDatabase)
+
+	var expected string
+	expected = os.Getenv("PREST_PG_DATABASE")
+	if len(expected) == 0 {
+		expected = "prest"
+	}
+	if cfg.PGDatabase != expected {
+		t.Errorf("expected database: %s, got: %s", expected, cfg.PGDatabase)
 	}
 
 	os.Unsetenv("PREST_CONF")
+	os.Unsetenv("PREST_JWT_DEFAULT")
 	os.Setenv("PREST_HTTP_PORT", "4000")
 
 	viperCfg()
@@ -280,7 +289,7 @@ func Test_portFromEnv(t *testing.T) {
 }
 
 func Test_Auth(t *testing.T) {
-	os.Setenv("PREST_CONF", "./testdata/prest.toml")
+	os.Setenv("PREST_CONF", "../testdata/prest.toml")
 
 	viperCfg()
 	cfg := &Prest{}
@@ -293,6 +302,10 @@ func Test_Auth(t *testing.T) {
 		t.Errorf("expected auth.enabled to be: false, got: %v", cfg.AuthEnabled)
 	}
 
+	if cfg.AuthSchema != "public" {
+		t.Errorf("expected auth.schema to be: public, got: %s", cfg.AuthSchema)
+	}
+
 	if cfg.AuthTable != "prest_users" {
 		t.Errorf("expected auth.table to be: prest_users, got: %s", cfg.AuthTable)
 	}
@@ -311,12 +324,12 @@ func Test_Auth(t *testing.T) {
 
 	metadata := []string{"first_name", "last_name", "last_login"}
 	if len(cfg.AuthMetadata) != len(metadata) {
-		t.Errorf("expected auth.metadata to be: %d, got: %d", len(cfg.AuthMetadata), len(metadata))
+		t.Errorf("expected auth.metadata to be: %d, got: %d", len(metadata), len(cfg.AuthMetadata))
 	}
 
 	for i, v := range cfg.AuthMetadata {
 		if v != metadata[i] {
-			t.Errorf("expected auth.metadata field %d to be: %s, got: %s", i, v, metadata[i])
+			t.Errorf("expected auth.metadata field %d to be: %s, got: %s", i, metadata[i], v)
 		}
 	}
 }
diff --git a/controllers/auth_test.go b/controllers/auth_test.go
index 9bd05e1..eba4cc4 100644
--- a/controllers/auth_test.go
+++ b/controllers/auth_test.go
@@ -36,7 +36,7 @@ func Test_basicPasswordCheck(t *testing.T) {
 func Test_getSelectQuery(t *testing.T) {
 	config.Load()
 
-	expected := "SELECT * FROM prest_users WHERE username=$1 AND password=$2 LIMIT 1"
+	expected := "SELECT * FROM public.prest_users WHERE username=$1 AND password=$2 LIMIT 1"
 	query := getSelectQuery()
 
 	if query != expected {