diff --git a/.circleci/config.yml b/.circleci/config.yml index 1ee4bcc332b..e3ced2d6e28 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -28,17 +28,20 @@ jobs: docker: - image: circleci/golang:1.12 environment: - - GO111MODULE=on - - TEST_DATABASE_POSTGRESQL=postgres://test:test@localhost:5432/hydra?sslmode=disable - - TEST_DATABASE_MYSQL=root:test@(localhost:3306)/mysql?parseTime=true + - GO111MODULE=on + - TEST_DATABASE_POSTGRESQL=postgres://test:test@localhost:5432/hydra?sslmode=disable + - TEST_DATABASE_MYSQL=mysql://root:test@(localhost:3306)/mysql?parseTime=true + - TEST_DATABASE_COCKROACHDB=cockroach://root@localhost:26257/defaultdb?sslmode=disable - image: postgres:9.6 environment: - - POSTGRES_USER=test - - POSTGRES_PASSWORD=test - - POSTGRES_DB=hydra + - POSTGRES_USER=test + - POSTGRES_PASSWORD=test + - POSTGRES_DB=hydra - image: mysql:5.7 environment: - - MYSQL_ROOT_PASSWORD=test + - MYSQL_ROOT_PASSWORD=test + - image: cockroachdb/cockroach:v2.1.6 + command: start --insecure working_directory: /go/src/github.com/ory/hydra steps: - checkout @@ -52,8 +55,8 @@ jobs: paths: - "/go/pkg/mod" - run: go-acc -o coverage.txt ./... -- -failfast -timeout=20m -# Running race conditions requires parallel tests, otherwise it's worthless (which is the case) -# - run: go test -race -short $(go list ./... | grep -v cmd) + # Running race conditions requires parallel tests, otherwise it's worthless (which is the case) + # - run: go test -race -short $(go list ./... | grep -v cmd) - run: test -z "$CIRCLE_PR_NUMBER" && goveralls -service=circle-ci -coverprofile=coverage.txt -repotoken=$COVERALLS_REPO_TOKEN || echo "forks are not allowed to push to coveralls" test-e2e-memory: @@ -210,6 +213,57 @@ jobs: - run: ./test/e2e/circle-ci.bash postgres - run: ./test/e2e/circle-ci.bash postgres-jwt + test-e2e-cockroach: + docker: + - image: oryd/e2e-env:latest + environment: + - GO111MODULE=on + - TEST_DATABASE_COCKROACHDB=cockroach://root@localhost:26257/defaultdb?sslmode=disable + - image: cockroachdb/cockroach:v2.1.6 + command: start --insecure + working_directory: /go/src/github.com/ory/hydra + steps: + - checkout + # core node_modules cache + - restore_cache: + keys: + - v1-deps-{{ checksum "package-lock.json" }} + - v1-deps + - run: npm ci + - save_cache: + key: v1-deps-{{ checksum "package-lock.json" }} + # cache NPM modules and the folder with the Cypress binary + paths: + - ~/.npm + - ~/.cache + + # oauth2_client node_modules cache + - restore_cache: + keys: + - v1-deps-oauth2-client-{{ checksum "test/e2e/oauth2-client/package-lock.json" }} + - v1-deps + - run: cd test/e2e/oauth2-client; npm ci + - save_cache: + key: v1-deps-oauth2-client-{{ checksum "test/e2e/oauth2-client/package-lock.json" }} + # cache NPM modules and the folder with the Cypress binary + paths: + - ~/.npm + - ~/.cache + - /test/e2e/oauth2-client/node_modules + + # go modules cache + - restore_cache: + keys: + - go-mod-v1-{{ checksum "go.sum" }} + - run: go install . + - save_cache: + key: go-mod-v1-{{ checksum "go.sum" }} + paths: + - "/go/pkg/mod" + + - run: ./test/e2e/circle-ci.bash cockroach + - run: ./test/e2e/circle-ci.bash cockroach-jwt + test-e2e-plugin: docker: - image: oryd/e2e-env:latest @@ -360,6 +414,10 @@ workflows: filters: tags: only: /.*/ + - test-e2e-cockroach: + filters: + tags: + only: /.*/ - test-e2e-plugin: filters: tags: @@ -384,6 +442,7 @@ workflows: - test-e2e-memory - test-e2e-postgres - test-e2e-mysql + - test-e2e-cockroach - test-e2e-plugin filters: tags: @@ -406,4 +465,4 @@ workflows: tags: only: /.*/ branches: - ignore: /.*/ + ignore: /.*/ \ No newline at end of file diff --git a/Makefile b/Makefile index cd5827380e1..8feaa654d0a 100644 --- a/Makefile +++ b/Makefile @@ -11,21 +11,26 @@ tools: test: make test-resetdb make sqlbin - TEST_DATABASE_MYSQL='root:secret@(127.0.0.1:3444)/mysql?parseTime=true' \ - TEST_DATABASE_POSTGRESQL='postgres://postgres:secret@127.0.0.1:3445/hydra?sslmode=disable' \ - go-acc ./... -- -failfast -timeout=20m + TEST_DATABASE_MYSQL='mysql://root:secret@(127.0.0.1:3444)/mysql?parseTime=true' \ + TEST_DATABASE_POSTGRESQL='postgres://postgres:secret@127.0.0.1:3445/hydra?sslmode=disable' \ + TEST_DATABASE_COCKROACHDB='cockroach://root@127.0.0.1:3446/defaultdb?sslmode=disable' \ + go-acc ./... -- -failfast -timeout=20m docker rm -f hydra_test_database_mysql docker rm -f hydra_test_database_postgres + docker rm -f hydra_test_database_cockroach # Resets the test databases .PHONY: test-resetdb test-resetdb: docker kill hydra_test_database_mysql || true docker kill hydra_test_database_postgres || true + docker kill hydra_test_database_cockroach || true docker rm -f hydra_test_database_mysql || true docker rm -f hydra_test_database_postgres || true + docker rm -f hydra_test_database_cockroach || true docker run --rm --name hydra_test_database_mysql -p 3444:3306 -e MYSQL_ROOT_PASSWORD=secret -d mysql:5.7 docker run --rm --name hydra_test_database_postgres -p 3445:5432 -e POSTGRES_PASSWORD=secret -e POSTGRES_DB=hydra -d postgres:9.6 + docker run --rm --name hydra_test_database_cockroach -p 3446:26257 -d cockroachdb/cockroach:v2.1.6 start --insecure # Runs tests in short mode, without database adapters .PHONY: docker @@ -38,14 +43,17 @@ docker: .PHONY: e2e e2e: make test-resetdb - export TEST_DATABASE_MYSQL='root:secret@(127.0.0.1:3444)/mysql?parseTime=true' + export TEST_DATABASE_MYSQL='mysql://root:secret@(127.0.0.1:3444)/mysql?parseTime=true' export TEST_DATABASE_POSTGRESQL='postgres://postgres:secret@127.0.0.1:3445/hydra?sslmode=disable' + export TEST_DATABASE_COCKROACHDB='cockroach://root@127.0.0.1:3446/defaultdb?sslmode=disable' ./test/e2e/circle-ci.bash memory ./test/e2e/circle-ci.bash memory-jwt ./test/e2e/circle-ci.bash postgres ./test/e2e/circle-ci.bash postgres-jwt ./test/e2e/circle-ci.bash mysql ./test/e2e/circle-ci.bash mysql-jwt + ./test/e2e/circle-ci.bash cockroach + ./test/e2e/circle-ci.bash cockroach-jwt ./test/e2e/circle-ci.bash plugin ./test/e2e/circle-ci.bash plugin-jwt diff --git a/client/manager_sql.go b/client/manager_sql.go index 7776bf9d3b0..f53d58f7214 100644 --- a/client/manager_sql.go +++ b/client/manager_sql.go @@ -40,8 +40,9 @@ import ( ) var Migrations = map[string]*dbal.PackrMigrationSource{ - dbal.DriverMySQL: dbal.NewMustPackerMigrationSource(logrus.New(), AssetNames(), Asset, []string{"migrations/sql/shared", "migrations/sql/mysql"}, true), - dbal.DriverPostgreSQL: dbal.NewMustPackerMigrationSource(logrus.New(), AssetNames(), Asset, []string{"migrations/sql/shared", "migrations/sql/postgres"}, true), + dbal.DriverMySQL: dbal.NewMustPackerMigrationSource(logrus.New(), AssetNames(), Asset, []string{"migrations/sql/shared", "migrations/sql/mysql"}, true), + dbal.DriverPostgreSQL: dbal.NewMustPackerMigrationSource(logrus.New(), AssetNames(), Asset, []string{"migrations/sql/shared", "migrations/sql/postgres"}, true), + dbal.DriverCockroachDB: dbal.NewMustPackerMigrationSource(logrus.New(), AssetNames(), Asset, []string{"migrations/sql/cockroach"}, true), } func NewSQLManager(db *sqlx.DB, r InternalRegistry) *SQLManager { @@ -225,15 +226,15 @@ func (d *sqlData) ToClient() (*Client, error) { return c, nil } -func (m *SQLManager) PlanMigration() ([]*migrate.PlannedMigration, error) { +func (m *SQLManager) PlanMigration(dbName string) ([]*migrate.PlannedMigration, error) { migrate.SetTable("hydra_client_migration") - plan, _, err := migrate.PlanMigration(m.DB.DB, m.DB.DriverName(), Migrations[dbal.Canonicalize(m.DB.DriverName())], migrate.Up, 0) + plan, _, err := migrate.PlanMigration(m.DB.DB, dbal.Canonicalize(m.DB.DriverName()), Migrations[dbName], migrate.Up, 0) return plan, errors.WithStack(err) } -func (m *SQLManager) CreateSchemas() (int, error) { +func (m *SQLManager) CreateSchemas(dbName string) (int, error) { migrate.SetTable("hydra_client_migration") - n, err := migrate.Exec(m.DB.DB, m.DB.DriverName(), Migrations[dbal.Canonicalize(m.DB.DriverName())], migrate.Up) + n, err := migrate.Exec(m.DB.DB, dbal.Canonicalize(m.DB.DriverName()), Migrations[dbName], migrate.Up) if err != nil { return 0, errors.Wrapf(err, "Could not migrate sql schema, applied %d Migrations", n) } diff --git a/client/manager_test.go b/client/manager_test.go index ce148041cf2..579e544109b 100644 --- a/client/manager_test.go +++ b/client/manager_test.go @@ -27,13 +27,12 @@ import ( "sync" "testing" - "github.com/ory/hydra/internal" - _ "github.com/go-sql-driver/mysql" _ "github.com/lib/pq" "github.com/stretchr/testify/require" . "github.com/ory/hydra/client" + "github.com/ory/hydra/internal" "github.com/ory/x/sqlcon/dockertest" ) @@ -74,6 +73,20 @@ func connectToPG() { m.Unlock() } +func connectToCRDB() { + db, err := dockertest.ConnectToTestCockroachDB() + if err != nil { + log.Fatalf("Could not connect to database: %v", err) + } + + conf := internal.NewConfigurationWithDefaults() + reg := internal.NewRegistrySQL(conf, db) + + m.Lock() + clientManagers["cockroach"] = reg.ClientManager() + m.Unlock() +} + func TestManagers(t *testing.T) { conf := internal.NewConfigurationWithDefaults() reg := internal.NewRegistry(conf) @@ -84,6 +97,7 @@ func TestManagers(t *testing.T) { dockertest.Parallel([]func(){ connectToPG, connectToMySQL, + connectToCRDB, }) } @@ -92,7 +106,7 @@ func TestManagers(t *testing.T) { s, ok := m.(*SQLManager) if ok { CleanTestDB(t, s.DB) - x, err := s.CreateSchemas() + x, err := s.CreateSchemas(k) if err != nil { t.Fatal("Could not create schemas", err.Error()) } else { diff --git a/client/migrations/sql/cockroach/13.sql b/client/migrations/sql/cockroach/13.sql new file mode 100644 index 00000000000..ccb14a51260 --- /dev/null +++ b/client/migrations/sql/cockroach/13.sql @@ -0,0 +1,39 @@ +-- +migrate Up +CREATE TABLE IF NOT EXISTS hydra_client ( + id varchar(255) NOT NULL, + client_name text NOT NULL, + client_secret text NOT NULL, + redirect_uris text NOT NULL, + grant_types text NOT NULL, + response_types text NOT NULL, + scope text NOT NULL, + owner text NOT NULL, + policy_uri text NOT NULL, + tos_uri text NOT NULL, + client_uri text NOT NULL, + logo_uri text NOT NULL, + contacts text NOT NULL, + client_secret_expires_at INTEGER NOT NULL DEFAULT 0, + sector_identifier_uri text NOT NULL, + jwks text NOT NULL, + jwks_uri text NOT NULL, + request_uris text NOT NULL, + token_endpoint_auth_method VARCHAR(25) NOT NULL DEFAULT '', + request_object_signing_alg VARCHAR(10) NOT NULL DEFAULT '', + userinfo_signed_response_alg VARCHAR(10) NOT NULL DEFAULT '', + subject_type VARCHAR(15) NOT NULL DEFAULT '', + allowed_cors_origins text NOT NULL, + pk SERIAL PRIMARY KEY, + audience text NOT NULL, + created_at timestamp NOT NULL DEFAULT now(), + updated_at timestamp NOT NULL DEFAULT now(), + frontchannel_logout_uri TEXT NOT NULL DEFAULT '', + frontchannel_logout_session_required BOOL NOT NULL DEFAULT FALSE, + post_logout_redirect_uris TEXT NOT NULL DEFAULT '', + backchannel_logout_uri TEXT NOT NULL DEFAULT '', + backchannel_logout_session_required BOOL NOT NULL DEFAULT FALSE, + UNIQUE (id) +); + +-- +migrate Down +DROP TABLE hydra_client; diff --git a/client/sql_migration_files.go b/client/sql_migration_files.go index 5017d306cc3..f38b07fe7c6 100644 --- a/client/sql_migration_files.go +++ b/client/sql_migration_files.go @@ -1,5 +1,6 @@ -// Code generated by go-bindata. (@generated) DO NOT EDIT. +// Code generated by go-bindata. DO NOT EDIT. // sources: +// migrations/sql/cockroach/13.sql // migrations/sql/mysql/11.sql // migrations/sql/mysql/13.sql // migrations/sql/mysql/4.sql @@ -99,6 +100,26 @@ func (fi bindataFileInfo) Sys() interface{} { return nil } +var _migrationsSqlCockroach13Sql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x94\x54\x4d\x73\xda\x30\x10\x3d\xc7\xbf\x42\xb7\xc0\xb4\x99\x49\x33\x93\x53\x4e\x4e\x22\x5a\x4f\x5d\x48\x8d\xe9\x24\x27\x8d\x22\x2d\x46\xc1\x68\xdd\xd5\xba\x84\x7f\xdf\x31\xa4\x94\x8c\x4c\x3b\x5c\xf7\xbd\xa7\x7d\xab\xfd\xb8\xb8\x10\x1f\x56\xae\x22\xcd\x20\x66\x4d\x72\x57\xc8\xb4\x94\xa2\x4c\x6f\x73\x29\xb2\x91\x18\x4f\x4a\x21\x1f\xb3\x69\x39\x15\x8b\x8d\x25\xad\x4c\xed\xc0\xb3\x18\x24\x67\xce\x8a\x5f\x9a\xcc\x42\xd3\xe0\xea\xfa\x7a\xb8\xa5\x8e\x67\x79\xfe\x31\x39\xdb\x91\x94\xd7\x2b\x10\x0c\xaf\xdc\x83\x05\x30\x04\x1c\xa1\x04\xd6\x11\x18\x56\x2d\xb9\x10\xa1\x15\x69\xcf\x8a\x37\x0d\xc4\x18\x41\x68\xd0\x07\x38\x02\x07\x83\x4d\x6c\x06\xd7\x1e\x28\x8a\x36\x58\x3b\xb3\xe9\x2c\x44\x10\x63\xe8\x8d\xbf\x55\xd5\x07\xd5\x58\x61\xbf\x06\x3d\x6b\xc3\xb1\xd7\x77\x5f\xa4\xe0\xb5\x71\x04\x41\x69\x16\xd9\xb8\x94\x9f\x65\xb1\xe7\x8a\x7b\x39\x4a\x67\x79\x29\x2e\xbb\x0a\xc1\x30\x92\x72\x16\x3c\xbb\xb9\x03\xea\x4d\xfa\xb2\x5e\xc6\x09\xbb\x60\x2f\x9b\xe0\x67\x0b\xe1\x48\x37\x18\x97\xe0\x15\x78\xdb\xa0\xf3\xac\x74\xcb\x0b\xb5\x02\x5e\xa0\x15\x3f\xd2\xe2\xee\x4b\x5a\x0c\xae\x0e\xe6\x62\x6f\xf6\xfc\xfc\xe0\x65\x7c\x7e\xe9\xda\x1d\x5c\xe5\x9d\xaf\x94\xae\x2b\xb1\x57\x7f\xba\x3c\xa6\x6e\x03\x90\xf3\x73\xdc\xea\xc0\xaa\x7d\xf3\x3b\xfd\xff\xe5\xa1\xdd\x65\xed\x46\xe5\x2f\xfd\xa8\x57\x5d\xd7\xb8\x06\xab\x0c\x52\x50\x48\xae\x72\x3e\xfe\x8d\x66\x29\xa6\xb2\xc8\xd2\x5c\x3c\x14\xd9\xb7\xb4\x78\x12\x5f\xe5\x53\x27\x6e\xad\x03\x6f\x7a\x16\x81\x40\x33\xd8\xae\xaf\xec\x56\x10\x58\xaf\x9a\xd8\x80\xc7\xf5\x60\xd8\x55\xdc\xd8\x13\xd8\x73\x42\xcf\x66\xa1\xbd\x87\x5a\x75\x03\xd8\xee\x66\xb3\x94\x8f\xe5\x91\x22\xfb\x24\x01\x42\x70\xe8\x55\xd7\x2c\x47\x60\xc5\xed\x64\x92\xc7\xfa\x51\x9a\x4f\xe5\x76\x6f\x02\xff\x91\xbe\x5f\xe4\x7f\xe4\x7d\xd6\x66\x79\x9a\xd3\x1e\xc5\x89\x46\x67\xe3\xec\xfb\x4c\x8a\x81\xb3\xc3\x64\x78\x93\x24\x87\x47\xf0\x1e\xd7\x3e\xb9\x2f\x26\x0f\x6f\x47\xf0\xf0\xec\xdd\x24\xbf\x03\x00\x00\xff\xff\xb6\xb4\xbf\xf2\x2f\x05\x00\x00") + +func migrationsSqlCockroach13SqlBytes() ([]byte, error) { + return bindataRead( + _migrationsSqlCockroach13Sql, + "migrations/sql/cockroach/13.sql", + ) +} + +func migrationsSqlCockroach13Sql() (*asset, error) { + bytes, err := migrationsSqlCockroach13SqlBytes() + if err != nil { + return nil, err + } + + info := bindataFileInfo{name: "migrations/sql/cockroach/13.sql", size: 1327, mode: os.FileMode(420), modTime: time.Unix(1557391332, 0)} + a := &asset{bytes: bytes, info: info} + return a, nil +} + var _migrationsSqlMysql11Sql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xd2\xd5\x55\xd0\xce\xcd\x4c\x2f\x4a\x2c\x49\x55\x08\x2d\xe0\x0a\x0d\x70\x71\x0c\x71\x55\xc8\xa8\x4c\x29\x4a\x8c\x4f\xce\xc9\x4c\xcd\x2b\x51\x08\x76\x0d\x51\x48\x2c\x4d\xc9\x4c\xcd\x4b\x4e\xb5\x55\x57\xb7\xe6\x72\xf4\x09\x71\x0d\x52\x08\x71\x74\xf2\x41\x53\xe9\xeb\xef\xe2\xe9\x16\x09\x57\xac\x10\xe2\x1a\x11\xa2\xe0\xe7\x1f\xa2\xe0\x17\xea\xe3\x63\xcd\xc5\x85\x6c\x99\x4b\x7e\x79\x1e\x69\x26\x59\x73\x01\x02\x00\x00\xff\xff\x72\x1b\x3f\x00\xad\x00\x00\x00") func migrationsSqlMysql11SqlBytes() ([]byte, error) { @@ -114,7 +135,7 @@ func migrationsSqlMysql11Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/mysql/11.sql", size: 173, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/mysql/11.sql", size: 173, mode: os.FileMode(420), modTime: time.Unix(1553158135, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -134,7 +155,7 @@ func migrationsSqlMysql13Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/mysql/13.sql", size: 1075, mode: os.FileMode(420), modTime: time.Unix(1556269326, 0)} + info := bindataFileInfo{name: "migrations/sql/mysql/13.sql", size: 1075, mode: os.FileMode(420), modTime: time.Unix(1557296175, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -154,7 +175,7 @@ func migrationsSqlMysql4Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/mysql/4.sql", size: 559, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/mysql/4.sql", size: 559, mode: os.FileMode(420), modTime: time.Unix(1553158135, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -174,7 +195,7 @@ func migrationsSqlMysql8Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/mysql/8.sql", size: 209, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/mysql/8.sql", size: 209, mode: os.FileMode(420), modTime: time.Unix(1553158135, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -194,7 +215,7 @@ func migrationsSqlMysql9Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/mysql/9.sql", size: 362, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/mysql/9.sql", size: 362, mode: os.FileMode(420), modTime: time.Unix(1553158135, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -214,7 +235,7 @@ func migrationsSqlPostgres11Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/postgres/11.sql", size: 193, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/postgres/11.sql", size: 193, mode: os.FileMode(420), modTime: time.Unix(1553158135, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -234,7 +255,7 @@ func migrationsSqlPostgres13Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/postgres/13.sql", size: 797, mode: os.FileMode(420), modTime: time.Unix(1556269326, 0)} + info := bindataFileInfo{name: "migrations/sql/postgres/13.sql", size: 797, mode: os.FileMode(420), modTime: time.Unix(1557296175, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -254,7 +275,7 @@ func migrationsSqlPostgres4Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/postgres/4.sql", size: 640, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/postgres/4.sql", size: 640, mode: os.FileMode(420), modTime: time.Unix(1553158135, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -274,7 +295,7 @@ func migrationsSqlPostgres8Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/postgres/8.sql", size: 233, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/postgres/8.sql", size: 233, mode: os.FileMode(420), modTime: time.Unix(1553158135, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -294,7 +315,7 @@ func migrationsSqlPostgres9Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/postgres/9.sql", size: 428, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/postgres/9.sql", size: 428, mode: os.FileMode(420), modTime: time.Unix(1553158135, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -314,7 +335,7 @@ func migrationsSqlSharedGitattributes() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/shared/.gitattributes", size: 12, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/shared/.gitattributes", size: 12, mode: os.FileMode(420), modTime: time.Unix(1553158135, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -334,7 +355,7 @@ func migrationsSqlSharedGitkeep() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/shared/.gitkeep", size: 0, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/shared/.gitkeep", size: 0, mode: os.FileMode(420), modTime: time.Unix(1553158135, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -354,7 +375,7 @@ func migrationsSqlShared1Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/shared/1.sql", size: 559, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/shared/1.sql", size: 559, mode: os.FileMode(420), modTime: time.Unix(1553158135, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -374,7 +395,7 @@ func migrationsSqlShared10Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/shared/10.sql", size: 124, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/shared/10.sql", size: 124, mode: os.FileMode(420), modTime: time.Unix(1553158135, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -394,7 +415,7 @@ func migrationsSqlShared12Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/shared/12.sql", size: 279, mode: os.FileMode(420), modTime: time.Unix(1555410663, 0)} + info := bindataFileInfo{name: "migrations/sql/shared/12.sql", size: 279, mode: os.FileMode(420), modTime: time.Unix(1553158135, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -414,7 +435,7 @@ func migrationsSqlShared2Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/shared/2.sql", size: 178, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/shared/2.sql", size: 178, mode: os.FileMode(420), modTime: time.Unix(1553158135, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -434,7 +455,7 @@ func migrationsSqlShared3Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/shared/3.sql", size: 890, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/shared/3.sql", size: 890, mode: os.FileMode(420), modTime: time.Unix(1553158135, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -454,7 +475,7 @@ func migrationsSqlShared5Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/shared/5.sql", size: 300, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/shared/5.sql", size: 300, mode: os.FileMode(420), modTime: time.Unix(1553158135, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -474,7 +495,7 @@ func migrationsSqlShared6Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/shared/6.sql", size: 159, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/shared/6.sql", size: 159, mode: os.FileMode(420), modTime: time.Unix(1553158135, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -494,7 +515,7 @@ func migrationsSqlShared7Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/shared/7.sql", size: 148, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/shared/7.sql", size: 148, mode: os.FileMode(420), modTime: time.Unix(1553158135, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -514,7 +535,7 @@ func migrationsSqlTestsGitkeep() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/tests/.gitkeep", size: 0, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/tests/.gitkeep", size: 0, mode: os.FileMode(420), modTime: time.Unix(1554881718, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -534,7 +555,7 @@ func migrationsSqlTests10_testSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/tests/10_test.sql", size: 787, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/tests/10_test.sql", size: 787, mode: os.FileMode(420), modTime: time.Unix(1554821189, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -554,7 +575,7 @@ func migrationsSqlTests11_testSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/tests/11_test.sql", size: 809, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/tests/11_test.sql", size: 809, mode: os.FileMode(420), modTime: time.Unix(1554821189, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -574,7 +595,7 @@ func migrationsSqlTests12_testSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/tests/12_test.sql", size: 847, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/tests/12_test.sql", size: 847, mode: os.FileMode(420), modTime: time.Unix(1554821189, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -594,7 +615,7 @@ func migrationsSqlTests13_testSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/tests/13_test.sql", size: 1085, mode: os.FileMode(420), modTime: time.Unix(1556269326, 0)} + info := bindataFileInfo{name: "migrations/sql/tests/13_test.sql", size: 1085, mode: os.FileMode(420), modTime: time.Unix(1557296175, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -614,7 +635,7 @@ func migrationsSqlTests1_testSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/tests/1_test.sql", size: 437, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/tests/1_test.sql", size: 437, mode: os.FileMode(420), modTime: time.Unix(1554821189, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -634,7 +655,7 @@ func migrationsSqlTests2_testSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/tests/2_test.sql", size: 466, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/tests/2_test.sql", size: 466, mode: os.FileMode(420), modTime: time.Unix(1554821189, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -654,7 +675,7 @@ func migrationsSqlTests3_testSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/tests/3_test.sql", size: 715, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/tests/3_test.sql", size: 715, mode: os.FileMode(420), modTime: time.Unix(1554821189, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -674,7 +695,7 @@ func migrationsSqlTests4_testSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/tests/4_test.sql", size: 715, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/tests/4_test.sql", size: 715, mode: os.FileMode(420), modTime: time.Unix(1554821189, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -694,7 +715,7 @@ func migrationsSqlTests5_testSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/tests/5_test.sql", size: 692, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/tests/5_test.sql", size: 692, mode: os.FileMode(420), modTime: time.Unix(1554821189, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -714,7 +735,7 @@ func migrationsSqlTests6_testSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/tests/6_test.sql", size: 716, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/tests/6_test.sql", size: 716, mode: os.FileMode(420), modTime: time.Unix(1554821189, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -734,7 +755,7 @@ func migrationsSqlTests7_testSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/tests/7_test.sql", size: 772, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/tests/7_test.sql", size: 772, mode: os.FileMode(420), modTime: time.Unix(1554821189, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -754,7 +775,7 @@ func migrationsSqlTests8_testSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/tests/8_test.sql", size: 772, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/tests/8_test.sql", size: 772, mode: os.FileMode(420), modTime: time.Unix(1554821189, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -774,7 +795,7 @@ func migrationsSqlTests9_testSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/tests/9_test.sql", size: 772, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/tests/9_test.sql", size: 772, mode: os.FileMode(420), modTime: time.Unix(1554821189, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -831,6 +852,7 @@ func AssetNames() []string { // _bindata is a table, holding each asset generator, mapped to its name. var _bindata = map[string]func() (*asset, error){ + "migrations/sql/cockroach/13.sql": migrationsSqlCockroach13Sql, "migrations/sql/mysql/11.sql": migrationsSqlMysql11Sql, "migrations/sql/mysql/13.sql": migrationsSqlMysql13Sql, "migrations/sql/mysql/4.sql": migrationsSqlMysql4Sql, @@ -910,6 +932,9 @@ type bintree struct { var _bintree = &bintree{nil, map[string]*bintree{ "migrations": &bintree{nil, map[string]*bintree{ "sql": &bintree{nil, map[string]*bintree{ + "cockroach": &bintree{nil, map[string]*bintree{ + "13.sql": &bintree{migrationsSqlCockroach13Sql, map[string]*bintree{}}, + }}, "mysql": &bintree{nil, map[string]*bintree{ "11.sql": &bintree{migrationsSqlMysql11Sql, map[string]*bintree{}}, "13.sql": &bintree{migrationsSqlMysql13Sql, map[string]*bintree{}}, diff --git a/client/validator_test.go b/client/validator_test.go index 61dd4e2f590..a76cc6fafea 100644 --- a/client/validator_test.go +++ b/client/validator_test.go @@ -27,15 +27,13 @@ import ( "testing" "github.com/spf13/viper" - - "github.com/ory/hydra/driver/configuration" - - . "github.com/ory/hydra/client" - "github.com/ory/hydra/internal" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" jose "gopkg.in/square/go-jose.v2" + + . "github.com/ory/hydra/client" + "github.com/ory/hydra/driver/configuration" + "github.com/ory/hydra/internal" ) func TestValidate(t *testing.T) { diff --git a/client/x_manager_sql_migrations_test.go b/client/x_manager_sql_migrations_test.go index 7072e576bbc..ca078128948 100644 --- a/client/x_manager_sql_migrations_test.go +++ b/client/x_manager_sql_migrations_test.go @@ -26,7 +26,6 @@ import ( "testing" "github.com/jmoiron/sqlx" - "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -34,11 +33,6 @@ import ( "github.com/ory/x/dbal/migratest" ) -var createMigrations = map[string]*dbal.PackrMigrationSource{ - dbal.DriverMySQL: dbal.NewMustPackerMigrationSource(logrus.New(), AssetNames(), Asset, []string{"migrations/sql/tests"}, true), - dbal.DriverPostgreSQL: dbal.NewMustPackerMigrationSource(logrus.New(), AssetNames(), Asset, []string{"migrations/sql/tests"}, true), -} - func CleanTestDB(t *testing.T, db *sqlx.DB) { _, err := db.Exec("DROP TABLE IF EXISTS hydra_client_migration") t.Logf("Unable to execute clean up query: %s", err) @@ -57,9 +51,12 @@ func TestXXMigrations(t *testing.T) { migratest.RunPackrMigrationTests( t, migratest.MigrationSchemas{Migrations}, - migratest.MigrationSchemas{createMigrations}, + migratest.MigrationSchemas{dbal.FindMatchingTestMigrations("migrations/sql/tests/", Migrations, AssetNames(), Asset)}, CleanTestDB, CleanTestDB, - func(t *testing.T, db *sqlx.DB, _, step, steps int) { + func(t *testing.T, dbName string, db *sqlx.DB, _, step, steps int) { + if dbName == "cockroach" { + step += 12 + } id := fmt.Sprintf("%d-data", step+1) t.Run("poll="+id, func(t *testing.T) { s := NewSQLManager(db, nil) diff --git a/cmd/cli/handler_client.go b/cmd/cli/handler_client.go index 01aff2c7287..0cbfd5b1ebf 100644 --- a/cmd/cli/handler_client.go +++ b/cmd/cli/handler_client.go @@ -26,15 +26,14 @@ import ( "os" "strings" - "github.com/ory/hydra/sdk/go/hydra/client/admin" - "github.com/ory/hydra/sdk/go/hydra/models" - "github.com/ory/x/pointerx" - "github.com/spf13/cobra" + "github.com/ory/hydra/sdk/go/hydra/client/admin" + "github.com/ory/hydra/sdk/go/hydra/models" "github.com/ory/hydra/x" "github.com/ory/x/cmdx" "github.com/ory/x/flagx" + "github.com/ory/x/pointerx" ) type ClientHandler struct{} diff --git a/cmd/cli/handler_migrate.go b/cmd/cli/handler_migrate.go index fb1e1a6254c..bdb6458ed23 100644 --- a/cmd/cli/handler_migrate.go +++ b/cmd/cli/handler_migrate.go @@ -23,6 +23,7 @@ package cli import ( "bufio" "fmt" + "net/url" "os" "strings" @@ -31,10 +32,9 @@ import ( "github.com/ory/hydra/driver" "github.com/ory/hydra/driver/configuration" - "github.com/ory/x/logrusx" - "github.com/ory/x/cmdx" "github.com/ory/x/flagx" + "github.com/ory/x/logrusx" ) type MigrateHandler struct{} @@ -74,7 +74,16 @@ func (h *MigrateHandler) MigrateSQL(cmd *cobra.Command, args []string) { return } - plan, err := reg.SchemaMigrationPlan() + u, err := url.Parse(d.Configuration().DSN()) + if err != nil { + fmt.Println(cmd.UsageString()) + fmt.Println("") + fmt.Println(err) + os.Exit(1) + return + } + + plan, err := reg.SchemaMigrationPlan(u.Scheme) cmdx.Must(err, "An error occurred planning migrations: %s", err) fmt.Println("The following migration is planned:") @@ -90,7 +99,7 @@ func (h *MigrateHandler) MigrateSQL(cmd *cobra.Command, args []string) { } } - n, err := reg.CreateSchemas() + n, err := reg.CreateSchemas(u.Scheme) cmdx.Must(err, "An error occurred while connecting to SQL: %s", err) fmt.Printf("Successfully applied %d SQL migrations!\n", n) } diff --git a/consent/manager_sql.go b/consent/manager_sql.go index 75bf95b1077..f80ba3f72f2 100644 --- a/consent/manager_sql.go +++ b/consent/manager_sql.go @@ -51,15 +51,15 @@ func NewSQLManager(db *sqlx.DB, r InternalRegistry) *SQLManager { } } -func (m *SQLManager) PlanMigration() ([]*migrate.PlannedMigration, error) { +func (m *SQLManager) PlanMigration(dbName string) ([]*migrate.PlannedMigration, error) { migrate.SetTable("hydra_oauth2_authentication_consent_migration") - plan, _, err := migrate.PlanMigration(m.DB.DB, m.DB.DriverName(), Migrations[dbal.Canonicalize(m.DB.DriverName())], migrate.Up, 0) + plan, _, err := migrate.PlanMigration(m.DB.DB, dbal.Canonicalize(m.DB.DriverName()), Migrations[dbName], migrate.Up, 0) return plan, errors.WithStack(err) } -func (m *SQLManager) CreateSchemas() (int, error) { +func (m *SQLManager) CreateSchemas(dbName string) (int, error) { migrate.SetTable("hydra_oauth2_authentication_consent_migration") - n, err := migrate.Exec(m.DB.DB, m.DB.DriverName(), Migrations[dbal.Canonicalize(m.DB.DriverName())], migrate.Up) + n, err := migrate.Exec(m.DB.DB, dbal.Canonicalize(m.DB.DriverName()), Migrations[dbName], migrate.Up) if err != nil { return 0, errors.Wrapf(err, "Could not migrate sql schema, applied %d migrations", n) } diff --git a/consent/manager_test.go b/consent/manager_test.go index 2d3d2bfae61..c4da80c82e0 100644 --- a/consent/manager_test.go +++ b/consent/manager_test.go @@ -26,20 +26,17 @@ import ( "testing" "time" - "github.com/ory/hydra/x" - + _ "github.com/go-sql-driver/mysql" "github.com/jmoiron/sqlx" + _ "github.com/lib/pq" "github.com/spf13/viper" + "github.com/stretchr/testify/require" + . "github.com/ory/hydra/consent" "github.com/ory/hydra/driver" "github.com/ory/hydra/driver/configuration" "github.com/ory/hydra/internal" - - _ "github.com/go-sql-driver/mysql" - _ "github.com/lib/pq" - "github.com/stretchr/testify/require" - - . "github.com/ory/hydra/consent" + "github.com/ory/hydra/x" "github.com/ory/x/sqlcon/dockertest" ) @@ -64,16 +61,25 @@ func connectToMySQL(t *testing.T) *sqlx.DB { return db } +func connectToCockroach(t *testing.T) *sqlx.DB { + db, err := dockertest.ConnectToTestCockroachDB() + require.NoError(t, err) + t.Logf("Cleaning cockroach db...") + x.CleanSQL(t, db) + t.Logf("Cleaned cockroach db") + return db +} + func TestMain(m *testing.M) { flag.Parse() runner := dockertest.Register() runner.Exit(m.Run()) } -func createSQL(db *sqlx.DB) driver.Registry { +func createSQL(dbName string, db *sqlx.DB) driver.Registry { conf := internal.NewConfigurationWithDefaults() reg := internal.NewRegistrySQL(conf, db) - if _, err := reg.CreateSchemas(); err != nil { + if _, err := reg.CreateSchemas(dbName); err != nil { panic(err) } @@ -86,16 +92,21 @@ func TestManagers(t *testing.T) { regs["memory"] = internal.NewRegistry(conf) if !testing.Short() { - var p, m *sqlx.DB + var p, m, c *sqlx.DB dockertest.Parallel([]func(){ func() { p = connectToPostgres(t) - }, func() { + }, + func() { m = connectToMySQL(t) }, + func() { + c = connectToCockroach(t) + }, }) - regs["postgres"] = createSQL(p) - regs["mysql"] = createSQL(m) + regs["postgres"] = createSQL("postgres", p) + regs["mysql"] = createSQL("mysql", m) + regs["cockroach"] = createSQL("cockroach", c) } for k, m := range regs { diff --git a/consent/migrations/sql/cockroach/12.sql b/consent/migrations/sql/cockroach/12.sql new file mode 100644 index 00000000000..10e4d04e1f0 --- /dev/null +++ b/consent/migrations/sql/cockroach/12.sql @@ -0,0 +1,117 @@ +-- +migrate Up +CREATE TABLE hydra_oauth2_consent_request ( + challenge varchar(40) NOT NULL PRIMARY KEY, + verifier varchar(40) NOT NULL, + client_id varchar(255) NOT NULL, + subject varchar(255) NOT NULL, + request_url text NOT NULL, + skip bool NOT NULL, + requested_scope text NOT NULL, + csrf varchar(40) NOT NULL, + authenticated_at timestamp NULL, + requested_at timestamp NOT NULL DEFAULT now(), + oidc_context text NOT NULL, + forced_subject_identifier VARCHAR(255) NULL DEFAULT '', + login_session_id VARCHAR(40) NULL, + login_challenge VARCHAR(40) NULL, + requested_at_audience text NULL DEFAULT '', + acr text NULL DEFAULT '', + context TEXT NOT NULL DEFAULT '{}', + INDEX (client_id), + INDEX (subject), + INDEX (login_session_id), + INDEX (login_challenge), + UNIQUE INDEX (verifier) +); +CREATE TABLE hydra_oauth2_authentication_request ( + challenge varchar(40) NOT NULL PRIMARY KEY, + requested_scope text NOT NULL, + verifier varchar(40) NOT NULL, + csrf varchar(40) NOT NULL, + subject varchar(255) NOT NULL, + request_url text NOT NULL, + skip bool NOT NULL, + client_id varchar(255) NOT NULL, + requested_at timestamp NOT NULL DEFAULT now(), + authenticated_at timestamp NULL, + oidc_context text NOT NULL, + login_session_id VARCHAR(40) NULL DEFAULT '', + requested_at_audience text NULL DEFAULT '', + INDEX (client_id), + INDEX (subject), + INDEX (login_session_id), + UNIQUE INDEX (verifier) +); +CREATE TABLE hydra_oauth2_authentication_session ( + id varchar(40) NOT NULL PRIMARY KEY, + authenticated_at timestamp NOT NULL DEFAULT NOW(), + subject varchar(255) NOT NULL, + remember bool NOT NULL DEFAULT FALSE +); +CREATE TABLE hydra_oauth2_consent_request_handled ( + challenge varchar(40) NOT NULL PRIMARY KEY, + granted_scope text NOT NULL, + remember bool NOT NULL, + remember_for int NOT NULL, + error text NOT NULL, + requested_at timestamp NOT NULL DEFAULT now(), + session_access_token text NOT NULL, + session_id_token text NOT NULL, + authenticated_at timestamp NULL, + was_used bool NOT NULL, + granted_at_audience TEXT NULL DEFAULT '' +); +CREATE TABLE hydra_oauth2_authentication_request_handled ( + challenge varchar(40) NOT NULL PRIMARY KEY, + subject varchar(255) NOT NULL, + remember bool NOT NULL, + remember_for int NOT NULL, + error text NOT NULL, + acr text NOT NULL, + requested_at timestamp NOT NULL DEFAULT now(), + authenticated_at timestamp NULL, + was_used bool NOT NULL, + forced_subject_identifier VARCHAR(255) NULL DEFAULT '', + context TEXT NOT NULL DEFAULT '{}' +); +CREATE TABLE hydra_oauth2_obfuscated_authentication_session ( + subject varchar(255) NOT NULL, + client_id varchar(255) NOT NULL, + subject_obfuscated varchar(255) NOT NULL, + PRIMARY KEY(subject, client_id), + INDEX (client_id, subject_obfuscated) +); +CREATE TABLE hydra_oauth2_logout_request ( + challenge varchar(36) NOT NULL PRIMARY KEY, + verifier varchar(36) NOT NULL, + subject varchar(255) NOT NULL, + sid varchar(36) NOT NULL, + client_id varchar(255), + request_url text NOT NULL, + redir_url text NOT NULL, + was_used bool NOT NULL default false, + accepted bool NOT NULL default false, + rejected bool NOT NULL default false, + rp_initiated bool NOT NULL default false, + INDEX (client_id), + UNIQUE INDEX (verifier) +); + +ALTER TABLE hydra_oauth2_consent_request_handled ADD CONSTRAINT hydra_oauth2_consent_request_handled_challenge_fk FOREIGN KEY (challenge) REFERENCES hydra_oauth2_consent_request(challenge) ON DELETE CASCADE; +ALTER TABLE hydra_oauth2_authentication_request_handled ADD CONSTRAINT hydra_oauth2_authentication_request_handled_challenge_fk FOREIGN KEY (challenge) REFERENCES hydra_oauth2_authentication_request(challenge) ON DELETE CASCADE; +ALTER TABLE hydra_oauth2_consent_request ADD CONSTRAINT hydra_oauth2_consent_request_client_id_fk FOREIGN KEY (client_id) REFERENCES hydra_client(id) ON DELETE CASCADE; +ALTER TABLE hydra_oauth2_authentication_request ADD CONSTRAINT hydra_oauth2_authentication_request_client_id_fk FOREIGN KEY (client_id) REFERENCES hydra_client(id) ON DELETE CASCADE; +ALTER TABLE hydra_oauth2_obfuscated_authentication_session ADD CONSTRAINT hydra_oauth2_obfuscated_authentication_session_client_id_fk FOREIGN KEY (client_id) REFERENCES hydra_client(id) ON DELETE CASCADE; +ALTER TABLE hydra_oauth2_authentication_request ADD CONSTRAINT hydra_oauth2_authentication_request_login_session_id_fk FOREIGN KEY (login_session_id) REFERENCES hydra_oauth2_authentication_session(id) ON DELETE CASCADE; +ALTER TABLE hydra_oauth2_consent_request ADD CONSTRAINT hydra_oauth2_consent_request_login_session_id_fk FOREIGN KEY (login_session_id) REFERENCES hydra_oauth2_authentication_session(id) ON DELETE SET NULL; +ALTER TABLE hydra_oauth2_consent_request ADD CONSTRAINT hydra_oauth2_consent_request_login_challenge_fk FOREIGN KEY (login_challenge) REFERENCES hydra_oauth2_authentication_request(challenge) ON DELETE SET NULL; +ALTER TABLE hydra_oauth2_logout_request ADD CONSTRAINT hydra_oauth2_logout_request_client_id_fk FOREIGN KEY (client_id) REFERENCES hydra_client(id) ON DELETE CASCADE; + +-- +migrate Down +DROP TABLE hydra_oauth2_consent_request_handled; +DROP TABLE hydra_oauth2_consent_request; +DROP TABLE hydra_oauth2_authentication_request_handled; +DROP TABLE hydra_oauth2_authentication_request; +DROP TABLE hydra_oauth2_authentication_session; +DROP TABLE hydra_oauth2_obfuscated_authentication_session; +DROP TABLE hydra_oauth2_logout_request; diff --git a/consent/sql_helper.go b/consent/sql_helper.go index 8390ab7fc2c..e3a84e885c3 100644 --- a/consent/sql_helper.go +++ b/consent/sql_helper.go @@ -44,6 +44,9 @@ var Migrations = map[string]*dbal.PackrMigrationSource{ "migrations/sql/shared", "migrations/sql/postgres", }, true), + "cockroach": dbal.NewMustPackerMigrationSource(logrus.New(), AssetNames(), Asset, []string{ + "migrations/sql/cockroach", + }, true), } var sqlParamsAuthenticationRequestHandled = []string{ diff --git a/consent/sql_migration_files.go b/consent/sql_migration_files.go index 23f50771905..1829662adad 100644 --- a/consent/sql_migration_files.go +++ b/consent/sql_migration_files.go @@ -1,5 +1,6 @@ -// Code generated by go-bindata. (@generated) DO NOT EDIT. +// Code generated by go-bindata. DO NOT EDIT. // sources: +// migrations/sql/cockroach/12.sql // migrations/sql/mysql/.gitkeep // migrations/sql/mysql/10.sql // migrations/sql/mysql/12.sql @@ -100,6 +101,26 @@ func (fi bindataFileInfo) Sys() interface{} { return nil } +var _migrationsSqlCockroach12Sql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xd4\x58\xcf\x73\xda\x3a\x10\x3e\xe3\xbf\x42\xb7\xc0\x3c\x32\xf3\x26\xef\xe5\x5d\x38\xf9\x61\xd1\x32\xa5\x26\x35\xa6\x4d\x4e\x1e\x21\xcb\xa0\xc6\x58\x54\x92\x93\x76\x3a\xfd\xdf\x3b\x06\xdb\xf8\xb7\x6c\x93\x64\xa6\x57\xeb\xdb\xd5\x7e\xbb\xdf\xee\x0a\xae\xaf\xc1\x5f\x7b\xba\xe5\x48\x12\xb0\x3e\x68\x53\x0b\xea\x36\x04\xb6\xfe\xff\x02\x82\xdd\x0f\x97\x23\x87\xa1\x50\xee\x6e\x1c\xcc\x02\x41\x02\xe9\x70\xf2\x2d\x24\x42\x82\xa1\x36\xc0\x3b\xe4\xfb\x24\xd8\x12\xf0\x84\x38\xde\x21\x3e\xfc\xf7\xef\x11\x30\x97\x36\x30\xd7\x8b\x05\xb8\xb3\xe6\x1f\x75\xeb\x01\x7c\x80\x0f\x63\x6d\xf0\x44\x38\xf5\x28\xe1\x95\xd8\xb1\x36\xc0\x3e\x8d\xdc\x53\x37\x05\xdc\xdc\xde\xe6\x10\x22\xdc\x7c\x25\x58\xd6\x9e\xc7\x91\x39\x21\xf7\x81\x24\xdf\x65\xce\xf6\x91\x1e\xc0\x86\x31\xbf\xc2\x80\xb8\x8e\xc0\xec\x40\x4a\x46\x58\x70\xaf\x2e\xdc\x28\x29\x24\x90\x14\xa3\xc8\x1e\x49\x20\xe9\x9e\x08\x89\xf6\x87\xb2\xf7\xfc\x69\x92\x1e\x03\xce\xf4\xf5\xc2\x06\x01\x7b\x1e\x8e\xc6\xda\x80\x51\x17\x47\x59\x3e\x46\x51\x0c\xc5\x63\x1c\x47\x71\x9e\x52\xe0\x50\x37\xba\xfb\x98\xce\xcf\xba\x35\x7d\xaf\x5b\x71\x36\xb2\x8e\xaf\xae\xc6\xda\xc0\x67\x5b\x1a\x38\x82\x08\x41\x59\x10\x65\x37\xc1\x1f\xf9\x9c\x9c\x9f\x30\xe7\x6a\x56\x40\xb2\x64\x1c\x14\xba\x94\x04\x38\x49\x58\xe9\x4e\x84\x79\xdd\x51\xc2\xcf\x86\xf7\x76\x39\x15\x57\x3f\x7f\x45\xa0\xb9\x69\xc0\x7b\x30\x4c\x15\x31\x3a\x7f\x8b\x13\x90\xf9\x52\x24\x58\x3a\x4a\x79\x45\x27\x6b\x73\xfe\x69\x0d\x41\x0c\x48\x34\x39\xd2\x46\x93\x06\xe9\x67\x6a\x1d\xdd\xd1\xb7\x03\x54\x72\x53\x76\x48\x83\x1c\x5f\xbc\x37\xd4\xed\xd8\x55\xdf\xea\x8e\x69\xec\x00\xa5\x90\xf3\x42\xeb\x24\xd8\x8b\x05\xf7\x12\xb2\x8a\x3d\x46\xb2\xca\x64\xbd\x41\x4f\x4d\x09\x2d\x16\xc1\x5c\x7e\x39\x16\x41\xad\x93\x3d\xd9\x6f\x08\xcf\xeb\x21\x75\x33\xd3\x17\x2b\xd8\xcc\xaa\xb0\x27\x9c\x1d\x0a\x5c\x9f\xb8\x9d\xbb\x65\xcb\x51\x50\xdf\x2b\xd5\x71\x66\x0e\x1c\x8f\x71\x40\x83\x9c\x11\xe1\x9c\xf1\x0a\x57\xdd\x74\x9c\x54\x1e\x61\x4c\x84\x70\x24\x7b\x24\x41\xb9\xa7\x52\x79\xd4\x00\xd4\xdd\xf0\x8c\x84\x13\x0a\xe2\x96\x28\x26\x99\xc9\x0a\xfb\x34\x4f\xf3\xc2\xee\x33\xd4\x7a\x97\xab\x9f\xb0\x7a\x15\xec\xbc\x5e\x5e\x73\x18\xd5\xa6\xbf\xf7\x2a\x56\xef\xbe\xe6\x8a\xb1\x8d\x17\x8a\x38\xe0\xda\xd1\xa1\xaa\x43\xeb\x67\x56\xe6\xba\x5a\x68\x46\x02\xc9\xa0\x1c\x83\xaa\x29\x9a\x7e\x1b\x83\xb2\x7b\xc5\x98\xf4\xd9\x96\x85\x8a\x77\xe7\x3f\xff\xb5\x7f\x77\x66\xb1\x2d\x84\x2b\x32\xa9\x2a\x98\x56\xe7\x52\xb1\x6d\x39\x71\x29\xaf\x3c\xa9\x56\x1c\x70\x89\x87\x42\x5f\x02\x0f\xf9\x82\x1c\xe5\x8f\xc9\x41\x2a\x61\x9c\x44\xb4\xd4\xb0\x83\x43\x03\x2a\x29\x52\x43\xab\xb6\x64\xc3\xe2\xd3\xf4\x85\x0d\xad\x2e\x2b\x42\x37\x0c\x30\x5d\x9a\x2b\xdb\xd2\xe7\xa6\xdd\xca\xe6\xfc\xba\x73\xbc\x47\x30\x5b\x5a\x70\xfe\xce\x8c\x2a\x0f\x86\xe7\x77\x1f\xb0\xe0\x0c\x5a\xd0\x9c\xc2\x55\xa3\xd3\xac\xc9\xd2\x04\x06\x5c\x40\x1b\x82\xa9\xbe\x9a\xea\x06\x9c\xd4\xf3\x51\x8c\xd2\x26\x5a\xcd\xa6\x97\xb1\xab\xf6\xdd\x97\x64\xf1\xf7\x5f\x97\x62\xa5\x92\x29\xd3\x48\xc5\x54\xa6\x71\x3a\x1b\x46\x67\x97\x57\xa3\x4f\x15\xde\x34\x6c\xf5\x74\x6f\x62\xa0\xb4\xfe\x53\x6b\x50\x7c\x6d\x97\xa2\x2f\x3d\xc7\xdb\xf6\x43\x6c\xd2\x99\xdb\x25\x8d\xf0\xd6\x6c\x56\xf0\x34\xcb\x5f\x95\x4e\xfd\x90\x2a\xfe\x00\x7f\x91\x51\xd5\x82\x53\xe1\xc9\xd0\x44\x29\x0f\x7d\x95\x2e\xd1\xb2\xff\xb1\x19\xec\x39\xd0\x0c\x6b\x79\xd7\x61\x31\x4e\xda\x1a\xd4\x03\x9b\xf7\x4c\x57\xbb\xd6\xf8\x58\x95\xf5\x78\xe5\xdc\xaa\x37\xcd\x57\x6e\xa2\xfd\x0e\x00\x00\xff\xff\xcd\x13\x83\x4b\xca\x14\x00\x00") + +func migrationsSqlCockroach12SqlBytes() ([]byte, error) { + return bindataRead( + _migrationsSqlCockroach12Sql, + "migrations/sql/cockroach/12.sql", + ) +} + +func migrationsSqlCockroach12Sql() (*asset, error) { + bytes, err := migrationsSqlCockroach12SqlBytes() + if err != nil { + return nil, err + } + + info := bindataFileInfo{name: "migrations/sql/cockroach/12.sql", size: 5322, mode: os.FileMode(420), modTime: time.Unix(1557332124, 0)} + a := &asset{bytes: bytes, info: info} + return a, nil +} + var _migrationsSqlMysqlGitkeep = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x01\x00\x00\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00") func migrationsSqlMysqlGitkeepBytes() ([]byte, error) { @@ -115,7 +136,7 @@ func migrationsSqlMysqlGitkeep() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/mysql/.gitkeep", size: 0, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/mysql/.gitkeep", size: 0, mode: os.FileMode(420), modTime: time.Unix(1553158135, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -135,7 +156,7 @@ func migrationsSqlMysql10Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/mysql/10.sql", size: 479, mode: os.FileMode(420), modTime: time.Unix(1556269326, 0)} + info := bindataFileInfo{name: "migrations/sql/mysql/10.sql", size: 479, mode: os.FileMode(420), modTime: time.Unix(1557296175, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -155,7 +176,7 @@ func migrationsSqlMysql12Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/mysql/12.sql", size: 267, mode: os.FileMode(420), modTime: time.Unix(1557155127, 0)} + info := bindataFileInfo{name: "migrations/sql/mysql/12.sql", size: 267, mode: os.FileMode(420), modTime: time.Unix(1557296175, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -175,7 +196,7 @@ func migrationsSqlMysql4Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/mysql/4.sql", size: 1002, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/mysql/4.sql", size: 1002, mode: os.FileMode(420), modTime: time.Unix(1553158135, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -195,7 +216,7 @@ func migrationsSqlMysql5Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/mysql/5.sql", size: 1462, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/mysql/5.sql", size: 1462, mode: os.FileMode(420), modTime: time.Unix(1553158135, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -215,7 +236,7 @@ func migrationsSqlMysql6Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/mysql/6.sql", size: 266, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/mysql/6.sql", size: 266, mode: os.FileMode(420), modTime: time.Unix(1553158135, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -235,7 +256,7 @@ func migrationsSqlMysql7Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/mysql/7.sql", size: 6246, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/mysql/7.sql", size: 6246, mode: os.FileMode(420), modTime: time.Unix(1553158135, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -255,7 +276,7 @@ func migrationsSqlMysql8Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/mysql/8.sql", size: 597, mode: os.FileMode(420), modTime: time.Unix(1555427407, 0)} + info := bindataFileInfo{name: "migrations/sql/mysql/8.sql", size: 597, mode: os.FileMode(420), modTime: time.Unix(1557296175, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -275,7 +296,7 @@ func migrationsSqlPostgresGitkeep() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/postgres/.gitkeep", size: 0, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/postgres/.gitkeep", size: 0, mode: os.FileMode(420), modTime: time.Unix(1553158135, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -295,7 +316,7 @@ func migrationsSqlPostgres10Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/postgres/10.sql", size: 447, mode: os.FileMode(420), modTime: time.Unix(1556269326, 0)} + info := bindataFileInfo{name: "migrations/sql/postgres/10.sql", size: 447, mode: os.FileMode(420), modTime: time.Unix(1557296175, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -315,7 +336,7 @@ func migrationsSqlPostgres12Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/postgres/12.sql", size: 253, mode: os.FileMode(420), modTime: time.Unix(1557155127, 0)} + info := bindataFileInfo{name: "migrations/sql/postgres/12.sql", size: 253, mode: os.FileMode(420), modTime: time.Unix(1557296175, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -335,7 +356,7 @@ func migrationsSqlPostgres4Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/postgres/4.sql", size: 558, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/postgres/4.sql", size: 558, mode: os.FileMode(420), modTime: time.Unix(1553158135, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -355,7 +376,7 @@ func migrationsSqlPostgres5Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/postgres/5.sql", size: 1199, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/postgres/5.sql", size: 1199, mode: os.FileMode(420), modTime: time.Unix(1553158135, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -375,7 +396,7 @@ func migrationsSqlPostgres6Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/postgres/6.sql", size: 162, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/postgres/6.sql", size: 162, mode: os.FileMode(420), modTime: time.Unix(1553158135, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -395,7 +416,7 @@ func migrationsSqlPostgres7Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/postgres/7.sql", size: 6376, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/postgres/7.sql", size: 6376, mode: os.FileMode(420), modTime: time.Unix(1553252510, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -415,7 +436,7 @@ func migrationsSqlPostgres8Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/postgres/8.sql", size: 349, mode: os.FileMode(420), modTime: time.Unix(1555003572, 0)} + info := bindataFileInfo{name: "migrations/sql/postgres/8.sql", size: 349, mode: os.FileMode(420), modTime: time.Unix(1557296175, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -435,7 +456,7 @@ func migrationsSqlSharedGitkeep() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/shared/.gitkeep", size: 0, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/shared/.gitkeep", size: 0, mode: os.FileMode(420), modTime: time.Unix(1553158135, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -455,7 +476,7 @@ func migrationsSqlShared1Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/shared/1.sql", size: 2263, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/shared/1.sql", size: 2263, mode: os.FileMode(420), modTime: time.Unix(1553158135, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -475,7 +496,7 @@ func migrationsSqlShared11Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/shared/11.sql", size: 256, mode: os.FileMode(420), modTime: time.Unix(1556269326, 0)} + info := bindataFileInfo{name: "migrations/sql/shared/11.sql", size: 256, mode: os.FileMode(420), modTime: time.Unix(1557296175, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -495,7 +516,7 @@ func migrationsSqlShared2Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/shared/2.sql", size: 714, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/shared/2.sql", size: 714, mode: os.FileMode(420), modTime: time.Unix(1553158135, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -515,7 +536,7 @@ func migrationsSqlShared3Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/shared/3.sql", size: 531, mode: os.FileMode(420), modTime: time.Unix(1556269326, 0)} + info := bindataFileInfo{name: "migrations/sql/shared/3.sql", size: 531, mode: os.FileMode(420), modTime: time.Unix(1557296175, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -535,7 +556,7 @@ func migrationsSqlShared9Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/shared/9.sql", size: 648, mode: os.FileMode(420), modTime: time.Unix(1556269326, 0)} + info := bindataFileInfo{name: "migrations/sql/shared/9.sql", size: 648, mode: os.FileMode(420), modTime: time.Unix(1557296175, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -555,7 +576,7 @@ func migrationsSqlTestsGitkeep() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/tests/.gitkeep", size: 0, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/tests/.gitkeep", size: 0, mode: os.FileMode(420), modTime: time.Unix(1554881718, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -575,7 +596,7 @@ func migrationsSqlTests10_testSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/tests/10_test.sql", size: 3156, mode: os.FileMode(420), modTime: time.Unix(1556269326, 0)} + info := bindataFileInfo{name: "migrations/sql/tests/10_test.sql", size: 3156, mode: os.FileMode(420), modTime: time.Unix(1557296175, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -595,7 +616,7 @@ func migrationsSqlTests11_testSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/tests/11_test.sql", size: 3172, mode: os.FileMode(420), modTime: time.Unix(1556794367, 0)} + info := bindataFileInfo{name: "migrations/sql/tests/11_test.sql", size: 3172, mode: os.FileMode(420), modTime: time.Unix(1557296175, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -615,7 +636,7 @@ func migrationsSqlTests12_testSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/tests/12_test.sql", size: 3491, mode: os.FileMode(420), modTime: time.Unix(1557155127, 0)} + info := bindataFileInfo{name: "migrations/sql/tests/12_test.sql", size: 3491, mode: os.FileMode(420), modTime: time.Unix(1557296175, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -635,7 +656,7 @@ func migrationsSqlTests1_testSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/tests/1_test.sql", size: 2299, mode: os.FileMode(420), modTime: time.Unix(1556269326, 0)} + info := bindataFileInfo{name: "migrations/sql/tests/1_test.sql", size: 2299, mode: os.FileMode(420), modTime: time.Unix(1557296175, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -655,7 +676,7 @@ func migrationsSqlTests2_testSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/tests/2_test.sql", size: 2533, mode: os.FileMode(420), modTime: time.Unix(1556269326, 0)} + info := bindataFileInfo{name: "migrations/sql/tests/2_test.sql", size: 2533, mode: os.FileMode(420), modTime: time.Unix(1557296175, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -675,7 +696,7 @@ func migrationsSqlTests3_testSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/tests/3_test.sql", size: 2645, mode: os.FileMode(420), modTime: time.Unix(1556269326, 0)} + info := bindataFileInfo{name: "migrations/sql/tests/3_test.sql", size: 2645, mode: os.FileMode(420), modTime: time.Unix(1557296175, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -695,7 +716,7 @@ func migrationsSqlTests4_testSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/tests/4_test.sql", size: 2739, mode: os.FileMode(420), modTime: time.Unix(1556269326, 0)} + info := bindataFileInfo{name: "migrations/sql/tests/4_test.sql", size: 2739, mode: os.FileMode(420), modTime: time.Unix(1557296175, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -715,7 +736,7 @@ func migrationsSqlTests5_testSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/tests/5_test.sql", size: 2739, mode: os.FileMode(420), modTime: time.Unix(1556269326, 0)} + info := bindataFileInfo{name: "migrations/sql/tests/5_test.sql", size: 2739, mode: os.FileMode(420), modTime: time.Unix(1557296175, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -735,7 +756,7 @@ func migrationsSqlTests6_testSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/tests/6_test.sql", size: 5877, mode: os.FileMode(420), modTime: time.Unix(1556269326, 0)} + info := bindataFileInfo{name: "migrations/sql/tests/6_test.sql", size: 5877, mode: os.FileMode(420), modTime: time.Unix(1557296175, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -755,7 +776,7 @@ func migrationsSqlTests7_testSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/tests/7_test.sql", size: 2753, mode: os.FileMode(420), modTime: time.Unix(1556269326, 0)} + info := bindataFileInfo{name: "migrations/sql/tests/7_test.sql", size: 2753, mode: os.FileMode(420), modTime: time.Unix(1557296175, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -775,7 +796,7 @@ func migrationsSqlTests8_testSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/tests/8_test.sql", size: 2805, mode: os.FileMode(420), modTime: time.Unix(1556269326, 0)} + info := bindataFileInfo{name: "migrations/sql/tests/8_test.sql", size: 2805, mode: os.FileMode(420), modTime: time.Unix(1557296175, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -795,7 +816,7 @@ func migrationsSqlTests9_testSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/tests/9_test.sql", size: 3118, mode: os.FileMode(420), modTime: time.Unix(1556269326, 0)} + info := bindataFileInfo{name: "migrations/sql/tests/9_test.sql", size: 3118, mode: os.FileMode(420), modTime: time.Unix(1557296175, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -852,6 +873,7 @@ func AssetNames() []string { // _bindata is a table, holding each asset generator, mapped to its name. var _bindata = map[string]func() (*asset, error){ + "migrations/sql/cockroach/12.sql": migrationsSqlCockroach12Sql, "migrations/sql/mysql/.gitkeep": migrationsSqlMysqlGitkeep, "migrations/sql/mysql/10.sql": migrationsSqlMysql10Sql, "migrations/sql/mysql/12.sql": migrationsSqlMysql12Sql, @@ -932,6 +954,9 @@ type bintree struct { var _bintree = &bintree{nil, map[string]*bintree{ "migrations": &bintree{nil, map[string]*bintree{ "sql": &bintree{nil, map[string]*bintree{ + "cockroach": &bintree{nil, map[string]*bintree{ + "12.sql": &bintree{migrationsSqlCockroach12Sql, map[string]*bintree{}}, + }}, "mysql": &bintree{nil, map[string]*bintree{ ".gitkeep": &bintree{migrationsSqlMysqlGitkeep, map[string]*bintree{}}, "10.sql": &bintree{migrationsSqlMysql10Sql, map[string]*bintree{}}, diff --git a/consent/strategy_default_test.go b/consent/strategy_default_test.go index 9440e42f044..2403beae97c 100644 --- a/consent/strategy_default_test.go +++ b/consent/strategy_default_test.go @@ -36,35 +36,28 @@ import ( "testing" "time" + jwtgo "github.com/dgrijalva/jwt-go" "github.com/julienschmidt/httprouter" "github.com/pborman/uuid" - "github.com/urfave/negroni" - - "github.com/ory/hydra/driver" - - "github.com/ory/hydra/sdk/go/hydra/client/admin" - "github.com/ory/hydra/sdk/go/hydra/models" - "github.com/ory/x/pointerx" - "github.com/ory/x/urlx" - - "github.com/ory/hydra/x" - - "github.com/spf13/viper" - "github.com/pkg/errors" + "github.com/spf13/viper" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - - "github.com/ory/hydra/driver/configuration" - "github.com/ory/hydra/internal" - - jwtgo "github.com/dgrijalva/jwt-go" + "github.com/urfave/negroni" "github.com/ory/fosite" "github.com/ory/fosite/token/jwt" "github.com/ory/hydra/client" . "github.com/ory/hydra/consent" + "github.com/ory/hydra/driver" + "github.com/ory/hydra/driver/configuration" + "github.com/ory/hydra/internal" hydra "github.com/ory/hydra/sdk/go/hydra/client" + "github.com/ory/hydra/sdk/go/hydra/client/admin" + "github.com/ory/hydra/sdk/go/hydra/models" + "github.com/ory/hydra/x" + "github.com/ory/x/pointerx" + "github.com/ory/x/urlx" ) func mustRSAKey() *rsa.PrivateKey { diff --git a/consent/x_manager_sql_migrations_test.go b/consent/x_manager_sql_migrations_test.go index a77052b3ac1..d61b0452755 100644 --- a/consent/x_manager_sql_migrations_test.go +++ b/consent/x_manager_sql_migrations_test.go @@ -5,25 +5,17 @@ import ( "fmt" "testing" - "github.com/ory/hydra/x" - - "github.com/ory/hydra/internal" - "github.com/jmoiron/sqlx" - "github.com/sirupsen/logrus" "github.com/stretchr/testify/require" "github.com/ory/hydra/client" "github.com/ory/hydra/consent" + "github.com/ory/hydra/internal" + "github.com/ory/hydra/x" "github.com/ory/x/dbal" "github.com/ory/x/dbal/migratest" ) -var createMigrations = map[string]*dbal.PackrMigrationSource{ - dbal.DriverMySQL: dbal.NewMustPackerMigrationSource(logrus.New(), consent.AssetNames(), consent.Asset, []string{"migrations/sql/tests"}, true), - dbal.DriverPostgreSQL: dbal.NewMustPackerMigrationSource(logrus.New(), consent.AssetNames(), consent.Asset, []string{"migrations/sql/tests"}, true), -} - func TestXXMigrations(t *testing.T) { if testing.Short() { t.SkipNow() @@ -40,9 +32,9 @@ func TestXXMigrations(t *testing.T) { migratest.RunPackrMigrationTests( t, migratest.MigrationSchemas{client.Migrations, consent.Migrations}, - migratest.MigrationSchemas{nil, createMigrations}, + migratest.MigrationSchemas{nil, dbal.FindMatchingTestMigrations("migrations/sql/tests/", consent.Migrations, consent.AssetNames(), consent.Asset)}, x.CleanSQL, x.CleanSQL, - func(t *testing.T, db *sqlx.DB, sk, step, steps int) { + func(t *testing.T, dbName string, db *sqlx.DB, sk, step, steps int) { if sk == 0 { t.Skip("Nothing to do...") return @@ -53,6 +45,9 @@ func TestXXMigrations(t *testing.T) { reg := internal.NewRegistrySQL(conf, db) kk := step + 1 + if dbName == "cockroach" { + kk += 11 + } if kk <= 2 { t.Skip("Skipping the first two entries were deleted in migration 7.sql login_session_id is not defined") return diff --git a/docs/config.yaml b/docs/config.yaml index 574578f829c..3ecfdb70dc3 100644 --- a/docs/config.yaml +++ b/docs/config.yaml @@ -232,6 +232,12 @@ serve: # # If dsn is starting with mysql:// MySQL will be used as storage backend: # dsn: mysql://user:password@tcp(host:123)/database +# +### CockroachDB +# +# If dsn is starting with cockroach:// CockroachDB will be used as storage backend: +# dsn: dsn=cockroach://user:password@host:123/database +# dsn: memory # dsn: dsn=postgres://user:password@host:123/database # dsn: mysql://user:password@tcp(host:123)/database diff --git a/driver/registry_sql.go b/driver/registry_sql.go index bbc6161f5d6..36c7fd1d04e 100644 --- a/driver/registry_sql.go +++ b/driver/registry_sql.go @@ -7,20 +7,18 @@ import ( "strings" "time" + "github.com/jmoiron/sqlx" "github.com/olekukonko/tablewriter" migrate "github.com/rubenv/sql-migrate" - "github.com/jmoiron/sqlx" - - "github.com/ory/hydra/oauth2" - "github.com/ory/hydra/x" - "github.com/ory/x/sqlcon" - "github.com/ory/x/urlx" - "github.com/ory/hydra/client" "github.com/ory/hydra/consent" "github.com/ory/hydra/jwk" + "github.com/ory/hydra/oauth2" + "github.com/ory/hydra/x" "github.com/ory/x/dbal" + "github.com/ory/x/sqlcon" + "github.com/ory/x/urlx" ) type RegistrySQL struct { @@ -38,8 +36,8 @@ func init() { } type schemaCreator interface { - CreateSchemas() (int, error) - PlanMigration() ([]*migrate.PlannedMigration, error) + CreateSchemas(dbName string) (int, error) + PlanMigration(dbName string) ([]*migrate.PlannedMigration, error) } func NewRegistrySQL() *RegistrySQL { @@ -88,7 +86,7 @@ func (m *RegistrySQL) DB() *sqlx.DB { return m.db } -func (m *RegistrySQL) SchemaMigrationPlan() (*tablewriter.Table, error) { +func (m *RegistrySQL) SchemaMigrationPlan(dbName string) (*tablewriter.Table, error) { names := map[int]string{ 0: "JSON Web Keys", 1: "OAuth 2.0 Clients", @@ -116,7 +114,7 @@ func (m *RegistrySQL) SchemaMigrationPlan() (*tablewriter.Table, error) { m.ConsentManager().(schemaCreator), m.OAuth2Storage().(schemaCreator), } { - plans, err := s.PlanMigration() + plans, err := s.PlanMigration(dbName) if err != nil { return nil, err } @@ -135,32 +133,32 @@ func (m *RegistrySQL) SchemaMigrationPlan() (*tablewriter.Table, error) { return table, nil } -func (m *RegistrySQL) CreateSchemas() (int, error) { +func (m *RegistrySQL) CreateSchemas(dbName string) (int, error) { var total int - m.Logger().Debugf("Applying %s SQL migrations...", m.db.DriverName()) + m.Logger().Debugf("Applying %s SQL migrations...", dbName) for k, s := range []schemaCreator{ m.KeyManager().(schemaCreator), m.ClientManager().(schemaCreator), m.ConsentManager().(schemaCreator), m.OAuth2Storage().(schemaCreator), } { - m.Logger().Debugf("Applying %s SQL migrations for manager: %T (%d)", m.db.DriverName(), s, k) - if c, err := s.CreateSchemas(); err != nil { + m.Logger().Debugf("Applying %s SQL migrations for manager: %T (%d)", dbName, s, k) + if c, err := s.CreateSchemas(dbName); err != nil { return c, err } else { - m.Logger().Debugf("Successfully applied %d %s SQL migrations from manager: %T (%d)", c, m.db.DriverName(), s, k) + m.Logger().Debugf("Successfully applied %d %s SQL migrations from manager: %T (%d)", c, dbName, s, k) total += c } } - m.Logger().Debugf("Applied %d %s SQL migrations", total, m.db.DriverName()) + m.Logger().Debugf("Applied %d %s SQL migrations", total, dbName) return total, nil } func (m *RegistrySQL) CanHandle(dsn string) bool { s := dbal.Canonicalize(urlx.ParseOrFatal(m.l, dsn).Scheme) - return s == dbal.DriverMySQL || s == dbal.DriverPostgreSQL + return s == dbal.DriverMySQL || s == dbal.DriverPostgreSQL || s == dbal.DriverCockroachDB } func (m *RegistrySQL) Ping() error { diff --git a/go.mod b/go.mod index 48abb80349a..ad51efc2982 100644 --- a/go.mod +++ b/go.mod @@ -44,7 +44,7 @@ require ( github.com/ory/go-acc v0.0.0-20181118080137-ddc355013f90 github.com/ory/graceful v0.1.1 github.com/ory/herodot v0.6.0 - github.com/ory/x v0.0.56 + github.com/ory/x v0.0.59 github.com/pborman/uuid v1.2.0 github.com/phayes/freeport v0.0.0-20171002181615-b8543db493a5 github.com/pkg/errors v0.8.1 diff --git a/go.sum b/go.sum index cd708577746..c3a595be4c7 100644 --- a/go.sum +++ b/go.sum @@ -353,7 +353,6 @@ github.com/googleapis/gax-go/v2 v2.0.4 h1:hU4mGcQI4DaAYW+IbTun+2qEZVFxK0ySjQLTbS github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/gopherjs/gopherjs v0.0.0-20181004151105-1babbf986f6f/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= -github.com/gorilla/context v1.1.1 h1:AWwleXJkX/nhcU9bZSnZoi3h/qGYqQAGhq6zZe/aQW8= github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= github.com/gorilla/handlers v1.4.0 h1:XulKRWSQK5uChr4pEgSE4Tc/OcmnU9GJuSwdog/tZsA= github.com/gorilla/handlers v1.4.0/go.mod h1:Qkdc/uu4tH4g6mTK6auzZ766c4CA0Ng8+o/OAirnOIQ= @@ -364,7 +363,6 @@ github.com/gorilla/pat v0.0.0-20180118222023-199c85a7f6d1/go.mod h1:YeAe0gNeiNT5 github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ= github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4= github.com/gorilla/sessions v1.1.2/go.mod h1:8KCfur6+4Mqcc6S0FEfKuN15Vl5MgXW92AE8ovaJD0w= -github.com/gorilla/sessions v1.1.3 h1:uXoZdcdA5XdXF3QzuSlheVRUvjl+1rKY7zBXL68L9RU= github.com/gorilla/sessions v1.1.3/go.mod h1:8KCfur6+4Mqcc6S0FEfKuN15Vl5MgXW92AE8ovaJD0w= github.com/gorilla/sessions v1.1.4-0.20181208214519-12bd4761fc66 h1:2i3OrAjARC9UWJ/mie/5liA3dOcO9hcXIe0QHQLrTQ0= github.com/gorilla/sessions v1.1.4-0.20181208214519-12bd4761fc66/go.mod h1:Ieo8HYsV0qN9WIJeic1HRzDxX9UY5BkplHncRmmZPwU= @@ -511,8 +509,8 @@ github.com/ory/graceful v0.1.1/go.mod h1:zqu70l95WrKHF4AZ6tXHvAqAvpY6M7g6ttaAVcM github.com/ory/herodot v0.5.1/go.mod h1:3BOneqcyBsVybCPAJoi92KN2BpJHcmDqAMcAAaJiJow= github.com/ory/herodot v0.6.0 h1:Dcs4yH1Qw1GIgGCvvvdafhT8xjwElTE//8xLmHtPEYA= github.com/ory/herodot v0.6.0/go.mod h1:3BOneqcyBsVybCPAJoi92KN2BpJHcmDqAMcAAaJiJow= -github.com/ory/x v0.0.56 h1:G+YPvsFXZK7+qiarF2djOPB6rz9gid9kgiVbUC1yq2k= -github.com/ory/x v0.0.56/go.mod h1:da8VE+hIbNK87ppdGvzRFpOgozsT0yKYm82MC/0eGaY= +github.com/ory/x v0.0.59 h1:5nJUtZh4gd8BP0fLj7dQzQdsK97Js8vhrwk6ppoCEeg= +github.com/ory/x v0.0.59/go.mod h1:da8VE+hIbNK87ppdGvzRFpOgozsT0yKYm82MC/0eGaY= github.com/parnurzeal/gorequest v0.2.15/go.mod h1:3Kh2QUMJoqw3icWAecsyzkpY7UzRfDhbRdTjtNwNiUE= github.com/pborman/uuid v1.2.0 h1:J7Q5mO4ysT1dv8hyrUGHb9+ooztCXu1D8MY8DZYsu3g= github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k= diff --git a/internal/mock_generator_rs256.go b/internal/mock_generator_rs256.go index 24dbaf94dba..031aec67b84 100644 --- a/internal/mock_generator_rs256.go +++ b/internal/mock_generator_rs256.go @@ -25,11 +25,11 @@ import ( "crypto/rsa" "crypto/x509" - "github.com/ory/hydra/jwk" - "github.com/pborman/uuid" "github.com/pkg/errors" "gopkg.in/square/go-jose.v2" + + "github.com/ory/hydra/jwk" ) type veryInsecureRS256Generator struct{} diff --git a/jwk/handler_test.go b/jwk/handler_test.go index 61830d69e59..622e272b3fa 100644 --- a/jwk/handler_test.go +++ b/jwk/handler_test.go @@ -28,16 +28,13 @@ import ( "testing" "github.com/spf13/viper" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + jose "gopkg.in/square/go-jose.v2" "github.com/ory/hydra/driver/configuration" - - "github.com/ory/hydra/x" - "github.com/ory/hydra/internal" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "gopkg.in/square/go-jose.v2" + "github.com/ory/hydra/x" ) func TestHandlerWellKnown(t *testing.T) { diff --git a/jwk/manager_sql.go b/jwk/manager_sql.go index 2bbb30d2797..791b03eb64b 100644 --- a/jwk/manager_sql.go +++ b/jwk/manager_sql.go @@ -54,6 +54,9 @@ var Migrations = map[string]*dbal.PackrMigrationSource{ "migrations/sql/shared", "migrations/sql/postgres", }, true), + dbal.DriverCockroachDB: dbal.NewMustPackerMigrationSource(logrus.New(), AssetNames(), Asset, []string{ + "migrations/sql/cockroach", + }, true), } type sqlData struct { @@ -65,21 +68,15 @@ type sqlData struct { Key string `db:"keydata"` } -func (m *SQLManager) PlanMigration() ([]*migrate.PlannedMigration, error) { +func (m *SQLManager) PlanMigration(dbName string) ([]*migrate.PlannedMigration, error) { migrate.SetTable("hydra_jwk_migration") - plan, _, err := migrate.PlanMigration(m.DB.DB, m.DB.DriverName(), Migrations[dbal.Canonicalize(m.DB.DriverName())], migrate.Up, 0) + plan, _, err := migrate.PlanMigration(m.DB.DB, dbal.Canonicalize(m.DB.DriverName()), Migrations[dbName], migrate.Up, 0) return plan, errors.WithStack(err) } -func (m *SQLManager) CreateSchemas() (int, error) { - database := m.DB.DriverName() - switch database { - case "pgx", "pq": - database = "postgres" - } - +func (m *SQLManager) CreateSchemas(dbName string) (int, error) { migrate.SetTable("hydra_jwk_migration") - n, err := migrate.Exec(m.DB.DB, m.DB.DriverName(), Migrations[database], migrate.Up) + n, err := migrate.Exec(m.DB.DB, dbal.Canonicalize(m.DB.DriverName()), Migrations[dbName], migrate.Up) if err != nil { return 0, errors.Wrapf(err, "Could not migrate sql schema, applied %d migrations", n) } diff --git a/jwk/manager_test.go b/jwk/manager_test.go index c634b5d3937..0fb3774c9a2 100644 --- a/jwk/manager_test.go +++ b/jwk/manager_test.go @@ -25,15 +25,13 @@ import ( "sync" "testing" - "github.com/ory/hydra/x" - - "github.com/ory/hydra/internal" - _ "github.com/go-sql-driver/mysql" _ "github.com/lib/pq" "github.com/stretchr/testify/require" + "github.com/ory/hydra/internal" . "github.com/ory/hydra/jwk" + "github.com/ory/hydra/x" "github.com/ory/x/sqlcon/dockertest" ) @@ -62,6 +60,13 @@ func connectToMySQL(t *testing.T) *SQLManager { return internal.NewRegistrySQL(internal.NewConfigurationWithDefaults(), db).KeyManager().(*SQLManager) } +func connectToCRDB(t *testing.T) *SQLManager { + db, err := dockertest.ConnectToTestCockroachDB() + require.NoError(t, err) + x.CleanSQL(t, db) + return internal.NewRegistrySQL(internal.NewConfigurationWithDefaults(), db).KeyManager().(*SQLManager) +} + func TestManager(t *testing.T) { conf := internal.NewConfigurationWithDefaults() reg := internal.NewRegistry(conf) @@ -79,6 +84,11 @@ func TestManager(t *testing.T) { managers["mysql"] = connectToMySQL(t) m.Unlock() }, + func() { + m.Lock() + managers["cockroach"] = connectToCRDB(t) + m.Unlock() + }, }) } @@ -88,7 +98,7 @@ func TestManager(t *testing.T) { for name, m := range managers { if m, ok := m.(*SQLManager); ok { - n, err := m.CreateSchemas() + n, err := m.CreateSchemas(name) require.NoError(t, err) t.Logf("Applied %d migrations to %s", n, name) } @@ -103,7 +113,7 @@ func TestManager(t *testing.T) { for name, m := range managers { if m, ok := m.(*SQLManager); ok { - n, err := m.CreateSchemas() + n, err := m.CreateSchemas(name) require.NoError(t, err) t.Logf("Applied %d migrations to %s", n, name) } diff --git a/jwk/migrations/sql/cockroach/4.sql b/jwk/migrations/sql/cockroach/4.sql new file mode 100644 index 00000000000..f265ceb7392 --- /dev/null +++ b/jwk/migrations/sql/cockroach/4.sql @@ -0,0 +1,13 @@ +-- +migrate Up +CREATE TABLE IF NOT EXISTS hydra_jwk ( + sid varchar(255) NOT NULL, + kid varchar(255) NOT NULL, + version int NOT NULL DEFAULT 0, + keydata text NOT NULL, + created_at TIMESTAMP NOT NULL DEFAULT NOW(), + pk SERIAL PRIMARY KEY, + UNIQUE INDEX (sid, kid) +); + +-- +migrate Down +DROP TABLE hydra_jwk; diff --git a/jwk/sql_migration_files.go b/jwk/sql_migration_files.go index 3b4232de32e..3dd848df319 100644 --- a/jwk/sql_migration_files.go +++ b/jwk/sql_migration_files.go @@ -1,5 +1,6 @@ -// Code generated by go-bindata. (@generated) DO NOT EDIT. +// Code generated by go-bindata. DO NOT EDIT. // sources: +// migrations/sql/cockroach/4.sql // migrations/sql/mysql/4.sql // migrations/sql/postgres/4.sql // migrations/sql/shared/1.sql @@ -75,6 +76,26 @@ func (fi bindataFileInfo) Sys() interface{} { return nil } +var _migrationsSqlCockroach4Sql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x7c\x90\x51\x4b\xc3\x30\x14\x85\x9f\x7b\x7f\xc5\x79\x6c\xb1\x03\x11\xf6\xb4\xa7\x68\xef\x20\xd8\xb5\x35\x4d\x70\x7b\x1a\x61\x09\x2e\x16\xbb\x91\x86\xcd\xfd\x7b\x51\x64\x0c\x04\x5f\xef\x3d\xdf\x81\xf3\xcd\x66\xb8\xfb\x08\x6f\xd1\x26\x0f\x73\xa4\x27\xc5\x42\x33\xb4\x78\xac\x19\x72\x89\xa6\xd5\xe0\xb5\xec\x75\x8f\xfd\xc5\x45\xbb\x7d\x3f\x0f\xc8\x29\x9b\x82\xc3\xc9\xc6\xdd\xde\xc6\xfc\x61\x3e\x2f\x7e\x82\x8d\xa9\xeb\x92\xb2\xe1\x9f\xdf\xc9\xc7\x29\x1c\x46\x84\x31\x5d\xcf\xa8\x78\x29\x4c\xad\x71\xff\x0d\xfb\x8b\xb3\xc9\x22\xf9\xcf\x74\x0b\xee\xa2\xb7\xc9\xbb\xad\x4d\xd0\x72\xc5\xbd\x16\xab\xee\x6f\x43\xd3\xbe\xe6\x45\x49\xd9\x71\x40\xcf\x4a\x8a\x1a\x9d\x92\x2b\xa1\x36\x78\xe6\x4d\x49\x99\x69\xe4\x8b\x61\xc8\xa6\xe2\x35\xf2\x29\xb8\x12\x43\x70\x05\x15\x0b\xa2\x5b\x13\xd5\xe1\x3c\x52\xa5\xda\xee\xd7\xc4\x75\xfb\x82\xbe\x02\x00\x00\xff\xff\xe3\x74\x1b\x99\x31\x01\x00\x00") + +func migrationsSqlCockroach4SqlBytes() ([]byte, error) { + return bindataRead( + _migrationsSqlCockroach4Sql, + "migrations/sql/cockroach/4.sql", + ) +} + +func migrationsSqlCockroach4Sql() (*asset, error) { + bytes, err := migrationsSqlCockroach4SqlBytes() + if err != nil { + return nil, err + } + + info := bindataFileInfo{name: "migrations/sql/cockroach/4.sql", size: 305, mode: os.FileMode(420), modTime: time.Unix(1557332124, 0)} + a := &asset{bytes: bytes, info: info} + return a, nil +} + var _migrationsSqlMysql4Sql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x7c\x8f\xb1\x6e\x83\x30\x14\x45\x77\xbe\xe2\x8e\xad\x5a\xbe\x80\xc9\xc5\x4f\x95\x55\x78\xa6\xae\x2d\x95\xc9\x42\x72\xd5\x38\x56\x12\x42\x12\x91\xfc\x7d\xa4\x2c\x81\x01\xf6\xab\x7b\xce\xc9\x73\xbc\xed\xe2\xff\xd0\x9d\xff\xe0\xfa\x4c\x54\x96\x0c\xac\xf8\xa8\x08\x9b\x5b\x18\x3a\xbf\x1d\x13\xa4\xd1\x0d\x1a\xa3\x6a\x61\x5a\x7c\x51\x5b\x64\xa5\x21\x61\x09\x8e\xd5\xb7\x23\x28\x96\xf4\xfb\xdc\xfb\x18\xae\x3e\x06\x7f\x39\x42\xf3\xe4\xe6\xe5\x14\xc3\x3b\x52\x0c\xaf\xc5\x02\x48\x48\x89\x3e\x41\xb1\x85\xe3\x1f\xf5\xc9\x24\x21\x9c\xd5\x5e\x71\x69\xa8\x26\xb6\x73\x8d\x6c\xaa\x2f\x0f\xe3\x7e\x2d\xa0\xd4\x95\xab\x19\x7d\x5a\xa2\x3f\x56\x8b\x2d\x6b\xce\x13\xa9\x59\xe5\x3d\x00\x00\xff\xff\x5d\xb2\x7a\x0d\x5e\x01\x00\x00") func migrationsSqlMysql4SqlBytes() ([]byte, error) { @@ -90,7 +111,7 @@ func migrationsSqlMysql4Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/mysql/4.sql", size: 350, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/mysql/4.sql", size: 350, mode: os.FileMode(420), modTime: time.Unix(1553158135, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -110,7 +131,7 @@ func migrationsSqlPostgres4Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/postgres/4.sql", size: 407, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/postgres/4.sql", size: 407, mode: os.FileMode(420), modTime: time.Unix(1554468419, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -130,7 +151,7 @@ func migrationsSqlShared1Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/shared/1.sql", size: 239, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/shared/1.sql", size: 239, mode: os.FileMode(420), modTime: time.Unix(1553246476, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -150,7 +171,7 @@ func migrationsSqlShared2Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/shared/2.sql", size: 150, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/shared/2.sql", size: 150, mode: os.FileMode(420), modTime: time.Unix(1553158135, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -170,7 +191,7 @@ func migrationsSqlShared3Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/shared/3.sql", size: 90, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/shared/3.sql", size: 90, mode: os.FileMode(420), modTime: time.Unix(1553158135, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -190,7 +211,7 @@ func migrationsSqlTestsGitkeep() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/tests/.gitkeep", size: 0, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/tests/.gitkeep", size: 0, mode: os.FileMode(420), modTime: time.Unix(1554881718, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -210,7 +231,7 @@ func migrationsSqlTests1_testSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/tests/1_test.sql", size: 126, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/tests/1_test.sql", size: 126, mode: os.FileMode(420), modTime: time.Unix(1554821189, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -230,7 +251,7 @@ func migrationsSqlTests2_testSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/tests/2_test.sql", size: 145, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/tests/2_test.sql", size: 145, mode: os.FileMode(420), modTime: time.Unix(1554821189, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -250,7 +271,7 @@ func migrationsSqlTests3_testSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/tests/3_test.sql", size: 145, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/tests/3_test.sql", size: 145, mode: os.FileMode(420), modTime: time.Unix(1554821189, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -270,7 +291,7 @@ func migrationsSqlTests4_testSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/tests/4_test.sql", size: 145, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/tests/4_test.sql", size: 145, mode: os.FileMode(420), modTime: time.Unix(1554821189, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -327,6 +348,7 @@ func AssetNames() []string { // _bindata is a table, holding each asset generator, mapped to its name. var _bindata = map[string]func() (*asset, error){ + "migrations/sql/cockroach/4.sql": migrationsSqlCockroach4Sql, "migrations/sql/mysql/4.sql": migrationsSqlMysql4Sql, "migrations/sql/postgres/4.sql": migrationsSqlPostgres4Sql, "migrations/sql/shared/1.sql": migrationsSqlShared1Sql, @@ -382,6 +404,9 @@ type bintree struct { var _bintree = &bintree{nil, map[string]*bintree{ "migrations": &bintree{nil, map[string]*bintree{ "sql": &bintree{nil, map[string]*bintree{ + "cockroach": &bintree{nil, map[string]*bintree{ + "4.sql": &bintree{migrationsSqlCockroach4Sql, map[string]*bintree{}}, + }}, "mysql": &bintree{nil, map[string]*bintree{ "4.sql": &bintree{migrationsSqlMysql4Sql, map[string]*bintree{}}, }}, diff --git a/jwk/x_manager_sql_migrations_test.go b/jwk/x_manager_sql_migrations_test.go index 42f745f1b23..3a0a582173c 100644 --- a/jwk/x_manager_sql_migrations_test.go +++ b/jwk/x_manager_sql_migrations_test.go @@ -25,25 +25,17 @@ import ( "fmt" "testing" - "github.com/ory/hydra/x" - - "github.com/ory/hydra/internal" - "github.com/jmoiron/sqlx" - "github.com/sirupsen/logrus" "github.com/stretchr/testify/require" "github.com/ory/hydra/client" + "github.com/ory/hydra/internal" . "github.com/ory/hydra/jwk" + "github.com/ory/hydra/x" "github.com/ory/x/dbal" "github.com/ory/x/dbal/migratest" ) -var createMigrations = map[string]*dbal.PackrMigrationSource{ - dbal.DriverMySQL: dbal.NewMustPackerMigrationSource(logrus.New(), AssetNames(), Asset, []string{"migrations/sql/tests"}, true), - dbal.DriverPostgreSQL: dbal.NewMustPackerMigrationSource(logrus.New(), AssetNames(), Asset, []string{"migrations/sql/tests"}, true), -} - func TestXXMigrations(t *testing.T) { if testing.Short() { t.SkipNow() @@ -55,11 +47,14 @@ func TestXXMigrations(t *testing.T) { migratest.RunPackrMigrationTests( t, migratest.MigrationSchemas{Migrations}, - migratest.MigrationSchemas{createMigrations}, + migratest.MigrationSchemas{dbal.FindMatchingTestMigrations("migrations/sql/tests/", Migrations, AssetNames(), Asset)}, x.CleanSQL, x.CleanSQL, - func(t *testing.T, db *sqlx.DB, k, m, steps int) { + func(t *testing.T, dbName string, db *sqlx.DB, k, m, steps int) { t.Run(fmt.Sprintf("poll=%d", k), func(t *testing.T) { + if dbName == "cockroach" { + k += 3 + } conf := internal.NewConfigurationWithDefaults() reg := internal.NewRegistrySQL(conf, db) diff --git a/oauth2/fosite_store_sql.go b/oauth2/fosite_store_sql.go index 67e0059c7cc..e6e087d387e 100644 --- a/oauth2/fosite_store_sql.go +++ b/oauth2/fosite_store_sql.go @@ -79,6 +79,9 @@ var Migrations = map[string]*dbal.PackrMigrationSource{ "migrations/sql/shared", "migrations/sql/postgres", }, true), + dbal.DriverCockroachDB: dbal.NewMustPackerMigrationSource(logrus.New(), AssetNames(), Asset, []string{ + "migrations/sql/cockroach", + }, true), } type transactionKey int @@ -192,9 +195,9 @@ func (s *sqlData) toRequest(session fosite.Session, cm client.Manager, logger lo return r, nil } -func (s *FositeSQLStore) PlanMigration() ([]*migrate.PlannedMigration, error) { +func (s *FositeSQLStore) PlanMigration(dbName string) ([]*migrate.PlannedMigration, error) { migrate.SetTable("hydra_oauth2_migration") - plan, _, err := migrate.PlanMigration(s.DB.DB, s.DB.DriverName(), Migrations[dbal.Canonicalize(s.DB.DriverName())], migrate.Up, 0) + plan, _, err := migrate.PlanMigration(s.DB.DB, dbal.Canonicalize(s.DB.DriverName()), Migrations[dbName], migrate.Up, 0) return plan, errors.WithStack(err) } @@ -298,9 +301,9 @@ func (s *FositeSQLStore) deleteSession(ctx context.Context, signature string, ta return nil } -func (s *FositeSQLStore) CreateSchemas() (int, error) { +func (s *FositeSQLStore) CreateSchemas(dbName string) (int, error) { migrate.SetTable("hydra_oauth2_migration") - n, err := migrate.Exec(s.DB.DB, s.DB.DriverName(), Migrations[dbal.Canonicalize(s.DB.DriverName())], migrate.Up) + n, err := migrate.Exec(s.DB.DB, dbal.Canonicalize(s.DB.DriverName()), Migrations[dbName], migrate.Up) if err != nil { return 0, errors.Wrapf(err, "Could not migrate sql schema, applied %d migrations", n) } diff --git a/oauth2/fosite_store_test.go b/oauth2/fosite_store_test.go index c3dd573f7b2..e504986a6f5 100644 --- a/oauth2/fosite_store_test.go +++ b/oauth2/fosite_store_test.go @@ -25,20 +25,17 @@ import ( "flag" "testing" - "github.com/ory/hydra/x" - _ "github.com/go-sql-driver/mysql" "github.com/jmoiron/sqlx" _ "github.com/lib/pq" "github.com/stretchr/testify/require" "github.com/ory/hydra/client" - "github.com/ory/hydra/driver/configuration" - "github.com/ory/hydra/driver" + "github.com/ory/hydra/driver/configuration" "github.com/ory/hydra/internal" - . "github.com/ory/hydra/oauth2" + "github.com/ory/hydra/x" "github.com/ory/x/sqlcon/dockertest" ) @@ -64,9 +61,16 @@ func connectToMySQL(t *testing.T) *sqlx.DB { return db } -func connectSQL(t *testing.T, conf *configuration.ViperProvider, db *sqlx.DB) driver.Registry { +func connectToCRDB(t *testing.T) *sqlx.DB { + db, err := dockertest.ConnectToTestCockroachDB() + require.NoError(t, err) + x.CleanSQL(t, db) + return db +} + +func connectSQL(t *testing.T, conf *configuration.ViperProvider, dbName string, db *sqlx.DB) driver.Registry { reg := internal.NewRegistrySQL(conf, db) - _, err := reg.CreateSchemas() + _, err := reg.CreateSchemas(dbName) require.NoError(t, err) return reg } @@ -79,7 +83,7 @@ func TestManagers(t *testing.T) { registries["memory"] = reg if !testing.Short() { - var p, m *sqlx.DB + var p, m, c *sqlx.DB dockertest.Parallel([]func(){ func() { p = connectToPG(t) @@ -87,9 +91,13 @@ func TestManagers(t *testing.T) { func() { m = connectToMySQL(t) }, + func() { + c = connectToCRDB(t) + }, }) - registries["postgres"] = connectSQL(t, conf, p) - registries["mysql"] = connectSQL(t, conf, m) + registries["postgres"] = connectSQL(t, conf, "postgres", p) + registries["mysql"] = connectSQL(t, conf, "mysql", m) + registries["cockroach"] = connectSQL(t, conf, "cockroach", c) } for k, store := range registries { diff --git a/oauth2/handler.go b/oauth2/handler.go index e4ccc4dec02..767d7a2d5e9 100644 --- a/oauth2/handler.go +++ b/oauth2/handler.go @@ -30,10 +30,6 @@ import ( "strings" "time" - "github.com/ory/hydra/driver/configuration" - - "github.com/ory/x/urlx" - jwt2 "github.com/dgrijalva/jwt-go" "github.com/julienschmidt/httprouter" "github.com/pkg/errors" @@ -43,7 +39,9 @@ import ( "github.com/ory/fosite/token/jwt" "github.com/ory/hydra/client" "github.com/ory/hydra/consent" + "github.com/ory/hydra/driver/configuration" "github.com/ory/hydra/x" + "github.com/ory/x/urlx" ) const ( diff --git a/oauth2/migrations/sql/cockroach/9.sql b/oauth2/migrations/sql/cockroach/9.sql new file mode 100644 index 00000000000..f24db3c083e --- /dev/null +++ b/oauth2/migrations/sql/cockroach/9.sql @@ -0,0 +1,108 @@ +-- +migrate Up +CREATE TABLE IF NOT EXISTS hydra_oauth2_access ( + signature varchar(255) NOT NULL PRIMARY KEY, + request_id varchar(40) NOT NULL, + requested_at timestamp NOT NULL DEFAULT now(), + client_id varchar(255) NOT NULL, + scope text NOT NULL, + granted_scope text NOT NULL, + form_data text NOT NULL, + session_data text NOT NULL, + subject varchar(255) NOT NULL DEFAULT '', + active bool NOT NULL DEFAULT TRUE, + requested_audience text NULL DEFAULT '', + granted_audience text NULL DEFAULT '', + challenge_id varchar(40) NULL, + UNIQUE (request_id), + INDEX (requested_at), + INDEX (client_id), + INDEX (challenge_id) +); +CREATE TABLE IF NOT EXISTS hydra_oauth2_refresh ( + signature varchar(255) NOT NULL PRIMARY KEY, + request_id varchar(40) NOT NULL, + requested_at timestamp NOT NULL DEFAULT now(), + client_id varchar(255) NOT NULL, + scope text NOT NULL, + granted_scope text NOT NULL, + form_data text NOT NULL, + session_data text NOT NULL, + subject varchar(255) NOT NULL DEFAULT '', + active bool NOT NULL DEFAULT TRUE, + requested_audience text NULL DEFAULT '', + granted_audience text NULL DEFAULT '', + challenge_id varchar(40) NULL, + UNIQUE (request_id), + INDEX (client_id), + INDEX (challenge_id) +); +CREATE TABLE IF NOT EXISTS hydra_oauth2_code ( + signature varchar(255) NOT NULL PRIMARY KEY, + request_id varchar(40) NOT NULL, + requested_at timestamp NOT NULL DEFAULT now(), + client_id varchar(255) NOT NULL, + scope text NOT NULL, + granted_scope text NOT NULL, + form_data text NOT NULL, + session_data text NOT NULL, + subject varchar(255) NOT NULL DEFAULT '', + active bool NOT NULL DEFAULT TRUE, + requested_audience text NULL DEFAULT '', + granted_audience text NULL DEFAULT '', + challenge_id varchar(40) NULL, + INDEX (client_id), + INDEX (challenge_id) +); +CREATE TABLE IF NOT EXISTS hydra_oauth2_oidc ( + signature varchar(255) NOT NULL PRIMARY KEY, + request_id varchar(40) NOT NULL, + requested_at timestamp NOT NULL DEFAULT now(), + client_id varchar(255) NOT NULL, + scope text NOT NULL, + granted_scope text NOT NULL, + form_data text NOT NULL, + session_data text NOT NULL, + subject varchar(255) NOT NULL DEFAULT '', + active bool NOT NULL DEFAULT TRUE, + requested_audience text NULL DEFAULT '', + granted_audience text NULL DEFAULT '', + challenge_id varchar(40) NULL, + INDEX (client_id), + INDEX (challenge_id) +); +CREATE TABLE IF NOT EXISTS hydra_oauth2_pkce ( + signature varchar(255) NOT NULL PRIMARY KEY, + request_id varchar(40) NOT NULL, + requested_at timestamp NOT NULL DEFAULT now(), + client_id varchar(255) NOT NULL, + scope text NOT NULL, + granted_scope text NOT NULL, + form_data text NOT NULL, + session_data text NOT NULL, + subject varchar(255) NOT NULL, + active bool NOT NULL DEFAULT TRUE, + requested_audience TEXT NULL DEFAULT '', + granted_audience TEXT NULL DEFAULT '', + challenge_id varchar(40) NULL, + INDEX (client_id), + INDEX (challenge_id) +); + +ALTER TABLE hydra_oauth2_access ADD CONSTRAINT hydra_oauth2_access_client_id_fk FOREIGN KEY (client_id) REFERENCES hydra_client(id) ON DELETE CASCADE; +ALTER TABLE hydra_oauth2_refresh ADD CONSTRAINT hydra_oauth2_refresh_client_id_fk FOREIGN KEY (client_id) REFERENCES hydra_client(id) ON DELETE CASCADE; +ALTER TABLE hydra_oauth2_code ADD CONSTRAINT hydra_oauth2_code_client_id_fk FOREIGN KEY (client_id) REFERENCES hydra_client(id) ON DELETE CASCADE; +ALTER TABLE hydra_oauth2_oidc ADD CONSTRAINT hydra_oauth2_oidc_client_id_fk FOREIGN KEY (client_id) REFERENCES hydra_client(id) ON DELETE CASCADE; +ALTER TABLE hydra_oauth2_pkce ADD CONSTRAINT hydra_oauth2_pkce_client_id_fk FOREIGN KEY (client_id) REFERENCES hydra_client(id) ON DELETE CASCADE; + +ALTER TABLE hydra_oauth2_access ADD CONSTRAINT hydra_oauth2_access_challenge_id_fk FOREIGN KEY (challenge_id) REFERENCES hydra_oauth2_consent_request_handled(challenge) ON DELETE CASCADE; +ALTER TABLE hydra_oauth2_refresh ADD CONSTRAINT hydra_oauth2_refresh_challenge_id_fk FOREIGN KEY (challenge_id) REFERENCES hydra_oauth2_consent_request_handled(challenge) ON DELETE CASCADE; +ALTER TABLE hydra_oauth2_code ADD CONSTRAINT hydra_oauth2_code_challenge_id_fk FOREIGN KEY (challenge_id) REFERENCES hydra_oauth2_consent_request_handled(challenge) ON DELETE CASCADE; +ALTER TABLE hydra_oauth2_oidc ADD CONSTRAINT hydra_oauth2_oidc_challenge_id_fk FOREIGN KEY (challenge_id) REFERENCES hydra_oauth2_consent_request_handled(challenge) ON DELETE CASCADE; +ALTER TABLE hydra_oauth2_pkce ADD CONSTRAINT hydra_oauth2_pkce_challenge_id_fk FOREIGN KEY (challenge_id) REFERENCES hydra_oauth2_consent_request_handled(challenge) ON DELETE CASCADE; + +-- +migrate Down +DROP TABLE hydra_oauth2_access; +DROP TABLE hydra_oauth2_refresh; +DROP TABLE hydra_oauth2_code; +DROP TABLE hydra_oauth2_oidc; +DROP TABLE hydra_oauth2_pkce; diff --git a/oauth2/oauth2_auth_code_test.go b/oauth2/oauth2_auth_code_test.go index 094b14a6df3..7da24168bae 100644 --- a/oauth2/oauth2_auth_code_test.go +++ b/oauth2/oauth2_auth_code_test.go @@ -35,25 +35,11 @@ import ( "testing" "time" - "github.com/ory/hydra/sdk/go/hydra/client/admin" - "github.com/ory/hydra/sdk/go/hydra/models" - "github.com/ory/x/pointerx" - "github.com/ory/x/urlx" - - "github.com/jmoiron/sqlx" - - "github.com/ory/hydra/x" - "github.com/ory/x/sqlcon/dockertest" - - "github.com/spf13/viper" - - "github.com/ory/hydra/driver" - "github.com/ory/hydra/driver/configuration" - "github.com/ory/hydra/internal" - djwt "github.com/dgrijalva/jwt-go" + "github.com/jmoiron/sqlx" "github.com/julienschmidt/httprouter" "github.com/sirupsen/logrus" + "github.com/spf13/viper" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "golang.org/x/oauth2" @@ -62,7 +48,16 @@ import ( "github.com/ory/fosite" "github.com/ory/fosite/token/jwt" hc "github.com/ory/hydra/client" + "github.com/ory/hydra/driver" + "github.com/ory/hydra/driver/configuration" + "github.com/ory/hydra/internal" hydra "github.com/ory/hydra/sdk/go/hydra/client" + "github.com/ory/hydra/sdk/go/hydra/client/admin" + "github.com/ory/hydra/sdk/go/hydra/models" + "github.com/ory/hydra/x" + "github.com/ory/x/pointerx" + "github.com/ory/x/sqlcon/dockertest" + "github.com/ory/x/urlx" ) func newCookieJar() http.CookieJar { @@ -159,7 +154,7 @@ func TestAuthCodeWithDefaultStrategy(t *testing.T) { } if !testing.Short() { - var p, m *sqlx.DB + var p, m, c *sqlx.DB dockertest.Parallel([]func(){ func() { p = connectToPG(t) @@ -167,16 +162,24 @@ func TestAuthCodeWithDefaultStrategy(t *testing.T) { func() { m = connectToMySQL(t) }, + func() { + c = connectToCRDB(t) + }, }) pr := internal.NewRegistrySQL(conf, p) - _, err := pr.CreateSchemas() + _, err := pr.CreateSchemas("postgres") require.NoError(t, err) regs["postgres"] = pr mr := internal.NewRegistrySQL(conf, m) - _, err = mr.CreateSchemas() + _, err = mr.CreateSchemas("mysql") require.NoError(t, err) regs["mysql"] = mr + + cr := internal.NewRegistrySQL(conf, c) + _, err = cr.CreateSchemas("cockroach") + require.NoError(t, err) + regs["cockroach"] = cr } for km, reg := range regs { diff --git a/oauth2/oauth2_client_credentials_test.go b/oauth2/oauth2_client_credentials_test.go index 54b361f4c6f..5cc30d1ed43 100644 --- a/oauth2/oauth2_client_credentials_test.go +++ b/oauth2/oauth2_client_credentials_test.go @@ -31,22 +31,18 @@ import ( "testing" "time" - "github.com/ory/hydra/x" - - "github.com/spf13/viper" - - "github.com/ory/hydra/driver/configuration" - "github.com/ory/hydra/internal" - - goauth2 "golang.org/x/oauth2" - "github.com/dgrijalva/jwt-go" + "github.com/spf13/viper" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + goauth2 "golang.org/x/oauth2" "golang.org/x/oauth2/clientcredentials" hc "github.com/ory/hydra/client" + "github.com/ory/hydra/driver/configuration" + "github.com/ory/hydra/internal" . "github.com/ory/hydra/oauth2" + "github.com/ory/hydra/x" ) func TestClientCredentials(t *testing.T) { diff --git a/oauth2/sql_migration_files.go b/oauth2/sql_migration_files.go index 67094671c38..57cf18cbcb4 100644 --- a/oauth2/sql_migration_files.go +++ b/oauth2/sql_migration_files.go @@ -1,5 +1,6 @@ -// Code generated by go-bindata. (@generated) DO NOT EDIT. +// Code generated by go-bindata. DO NOT EDIT. // sources: +// migrations/sql/cockroach/9.sql // migrations/sql/mysql/.gitkeep // migrations/sql/mysql/5.sql // migrations/sql/mysql/6.sql @@ -90,6 +91,26 @@ func (fi bindataFileInfo) Sys() interface{} { return nil } +var _migrationsSqlCockroach9Sql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x98\x41\x6f\xda\x30\x14\xc7\xcf\xf8\x53\xbc\x5b\x41\xa3\xd2\x54\xad\x27\x4e\x19\x79\x4c\xd1\xb2\xd0\x05\x47\x6a\x4f\x91\xeb\x3c\x48\x56\x48\x58\x6c\xda\xed\xdb\x4f\xa6\x04\x82\x42\x28\x9b\x80\xa1\x2d\x57\xbf\x7f\xe2\x9f\xed\xdf\x33\x11\xd7\xd7\xf0\x6e\x96\x4c\x72\xa1\x09\x82\x39\xeb\xfb\x68\x71\x04\x6e\x7d\x74\x11\x9c\x01\x78\x43\x0e\x78\xef\x8c\xf8\x08\xe2\x9f\x51\x2e\xc2\x4c\x2c\x74\x7c\x13\x0a\x29\x49\x29\x68\xb3\x96\x4a\x26\xa9\xd0\x8b\x9c\xe0\x59\xe4\x32\x16\x79\xfb\xe6\xf6\xb6\xb3\x7c\xd0\x0b\x5c\x17\xee\x7c\xe7\x8b\xe5\x3f\xc0\x67\x7c\xe8\xb2\x56\x4e\xdf\x17\xa4\x74\x98\x44\xeb\xf8\x87\xf7\x9b\xf4\x26\x41\x51\x28\x34\xe8\x64\x46\x4a\x8b\xd9\x7c\xf3\x3e\x1b\x07\x56\xe0\x72\x48\xb3\x97\x76\xa7\xcb\x5a\x72\x9a\x50\xba\xf5\xc2\xad\xf9\xbb\xac\xa5\x64\x36\x27\xd0\xf4\x43\x97\x47\x27\xb9\x48\xcd\x2c\xbb\xab\xe3\x2c\x9f\x85\x91\xd0\xa2\x52\x51\xa4\x54\x92\xa5\x35\xc5\xc5\xe3\x37\x92\xba\x66\x2b\x0a\xf4\xab\xab\x2e\x6b\x09\xa9\x93\x67\x82\xc7\x2c\x9b\x56\x13\xdc\x0f\x70\x7b\x2f\x16\x51\x42\xa9\x2c\x40\x2b\x6f\x2b\x56\xf3\x56\x4e\xc6\x62\x3a\xa5\x74\x42\x95\x13\x78\x5d\x40\xe0\x39\x5f\x03\x84\xf6\xe6\x9c\xcc\x1e\x3b\x9e\x8d\xf7\xeb\xc1\xe5\xd1\x94\x86\xd7\x27\x50\x1e\x2b\xcd\xd3\x61\x9d\xde\xc1\x62\xe5\x34\xce\x49\xc5\x8d\x59\xff\x95\x59\x47\x55\x48\x66\x11\x35\xfe\xfc\x6b\xfe\x9c\xc2\x94\x2c\x89\x64\x63\x4a\x63\xca\xdb\xa6\xcc\x9f\x64\x73\xa7\xfc\x96\x29\x7f\xae\x07\xc7\xfb\x5d\xb2\x55\xf4\xa8\xc9\x1d\x53\x0f\x66\xb9\x1c\xfd\x95\x1e\xbb\x3e\x80\x2d\xdb\x86\xfe\xd0\x1b\x71\xdf\x72\x3c\xbe\x2b\x12\xae\x27\x0a\xc7\x4f\x30\x18\xfa\xe8\x7c\xf2\x8c\x1f\x65\x04\xf0\x71\x80\x3e\x7a\x7d\x2c\xbc\x7b\xad\xb5\x4d\x6d\xe8\x81\x8d\x2e\x72\x84\xbe\x35\xea\x5b\x36\xf6\xea\xb1\x8a\xcf\xa7\x7d\x5c\xab\xcc\x79\xc1\x96\x3f\xca\xfb\xa8\x4c\xe0\xbc\x48\xcb\xdb\x7f\x1f\x92\x09\x9c\x17\x69\x79\xcd\xec\x43\x32\x81\x93\x20\x1d\xc5\xf4\x52\xfb\x54\xd1\xca\xbd\x55\xa5\x5b\x5b\x90\x2a\xb3\x82\xe2\xe6\x8c\x45\x1a\x4d\x29\xda\x3c\x7d\xc2\x76\xb8\x38\xfa\x03\x7b\xe6\xe2\xb8\x0f\x6c\xac\x8b\xe3\x3e\xb0\xfb\xfe\x16\x37\x2b\xff\x57\x63\x67\x2f\x29\xb3\xfd\xe1\x5d\x7d\xcb\xf6\x6a\xeb\x2b\xe5\xeb\x03\x46\xac\xfa\xaa\x39\xbe\xfa\xaa\xd9\xa4\x1e\xfb\x15\x00\x00\xff\xff\x15\x33\x61\x06\x58\x12\x00\x00") + +func migrationsSqlCockroach9SqlBytes() ([]byte, error) { + return bindataRead( + _migrationsSqlCockroach9Sql, + "migrations/sql/cockroach/9.sql", + ) +} + +func migrationsSqlCockroach9Sql() (*asset, error) { + bytes, err := migrationsSqlCockroach9SqlBytes() + if err != nil { + return nil, err + } + + info := bindataFileInfo{name: "migrations/sql/cockroach/9.sql", size: 4696, mode: os.FileMode(420), modTime: time.Unix(1557332124, 0)} + a := &asset{bytes: bytes, info: info} + return a, nil +} + var _migrationsSqlMysqlGitkeep = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x01\x00\x00\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00") func migrationsSqlMysqlGitkeepBytes() ([]byte, error) { @@ -105,7 +126,7 @@ func migrationsSqlMysqlGitkeep() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/mysql/.gitkeep", size: 0, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/mysql/.gitkeep", size: 0, mode: os.FileMode(420), modTime: time.Unix(1553158135, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -125,7 +146,7 @@ func migrationsSqlMysql5Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/mysql/5.sql", size: 361, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/mysql/5.sql", size: 361, mode: os.FileMode(420), modTime: time.Unix(1553158135, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -145,7 +166,7 @@ func migrationsSqlMysql6Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/mysql/6.sql", size: 194, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/mysql/6.sql", size: 194, mode: os.FileMode(420), modTime: time.Unix(1553158135, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -165,7 +186,7 @@ func migrationsSqlMysql7Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/mysql/7.sql", size: 2531, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/mysql/7.sql", size: 2531, mode: os.FileMode(420), modTime: time.Unix(1553158135, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -185,7 +206,7 @@ func migrationsSqlMysql9Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/mysql/9.sql", size: 7031, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/mysql/9.sql", size: 7031, mode: os.FileMode(420), modTime: time.Unix(1553158135, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -205,7 +226,7 @@ func migrationsSqlPostgresGitkeep() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/postgres/.gitkeep", size: 0, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/postgres/.gitkeep", size: 0, mode: os.FileMode(420), modTime: time.Unix(1553158135, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -225,7 +246,7 @@ func migrationsSqlPostgres5Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/postgres/5.sql", size: 314, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/postgres/5.sql", size: 314, mode: os.FileMode(420), modTime: time.Unix(1553158135, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -245,7 +266,7 @@ func migrationsSqlPostgres6Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/postgres/6.sql", size: 171, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/postgres/6.sql", size: 171, mode: os.FileMode(420), modTime: time.Unix(1553158135, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -265,7 +286,7 @@ func migrationsSqlPostgres7Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/postgres/7.sql", size: 1411, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/postgres/7.sql", size: 1411, mode: os.FileMode(420), modTime: time.Unix(1553158135, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -285,7 +306,7 @@ func migrationsSqlPostgres9Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/postgres/9.sql", size: 6976, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/postgres/9.sql", size: 6976, mode: os.FileMode(420), modTime: time.Unix(1553158135, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -305,7 +326,7 @@ func migrationsSqlShared1Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/shared/1.sql", size: 1542, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/shared/1.sql", size: 1542, mode: os.FileMode(420), modTime: time.Unix(1553158135, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -325,7 +346,7 @@ func migrationsSqlShared2Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/shared/2.sql", size: 552, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/shared/2.sql", size: 552, mode: os.FileMode(420), modTime: time.Unix(1553158135, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -345,7 +366,7 @@ func migrationsSqlShared3Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/shared/3.sql", size: 445, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/shared/3.sql", size: 445, mode: os.FileMode(420), modTime: time.Unix(1553158135, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -365,7 +386,7 @@ func migrationsSqlShared4Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/shared/4.sql", size: 638, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/shared/4.sql", size: 638, mode: os.FileMode(420), modTime: time.Unix(1553158135, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -385,7 +406,7 @@ func migrationsSqlShared8Sql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/shared/8.sql", size: 649, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/shared/8.sql", size: 649, mode: os.FileMode(420), modTime: time.Unix(1553158135, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -405,7 +426,7 @@ func migrationsSqlTestsGitkeep() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/tests/.gitkeep", size: 0, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/tests/.gitkeep", size: 0, mode: os.FileMode(420), modTime: time.Unix(1554881718, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -425,7 +446,7 @@ func migrationsSqlTests1_testSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/tests/1_test.sql", size: 913, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/tests/1_test.sql", size: 913, mode: os.FileMode(420), modTime: time.Unix(1554821189, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -445,7 +466,7 @@ func migrationsSqlTests2_testSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/tests/2_test.sql", size: 1001, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/tests/2_test.sql", size: 1001, mode: os.FileMode(420), modTime: time.Unix(1554821189, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -465,7 +486,7 @@ func migrationsSqlTests3_testSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/tests/3_test.sql", size: 1243, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/tests/3_test.sql", size: 1243, mode: os.FileMode(420), modTime: time.Unix(1554821189, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -485,7 +506,7 @@ func migrationsSqlTests4_testSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/tests/4_test.sql", size: 1313, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/tests/4_test.sql", size: 1313, mode: os.FileMode(420), modTime: time.Unix(1554821189, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -505,7 +526,7 @@ func migrationsSqlTests5_testSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/tests/5_test.sql", size: 1313, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/tests/5_test.sql", size: 1313, mode: os.FileMode(420), modTime: time.Unix(1554821189, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -525,7 +546,7 @@ func migrationsSqlTests6_testSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/tests/6_test.sql", size: 1313, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/tests/6_test.sql", size: 1313, mode: os.FileMode(420), modTime: time.Unix(1554821189, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -545,7 +566,7 @@ func migrationsSqlTests7_testSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/tests/7_test.sql", size: 1683, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/tests/7_test.sql", size: 1683, mode: os.FileMode(420), modTime: time.Unix(1554821189, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -565,7 +586,7 @@ func migrationsSqlTests8_testSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/tests/8_test.sql", size: 1783, mode: os.FileMode(420), modTime: time.Unix(1551433226, 0)} + info := bindataFileInfo{name: "migrations/sql/tests/8_test.sql", size: 1783, mode: os.FileMode(420), modTime: time.Unix(1554821189, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -585,7 +606,7 @@ func migrationsSqlTests9_testSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "migrations/sql/tests/9_test.sql", size: 4205, mode: os.FileMode(420), modTime: time.Unix(1556269326, 0)} + info := bindataFileInfo{name: "migrations/sql/tests/9_test.sql", size: 4205, mode: os.FileMode(420), modTime: time.Unix(1557296175, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -642,6 +663,7 @@ func AssetNames() []string { // _bindata is a table, holding each asset generator, mapped to its name. var _bindata = map[string]func() (*asset, error){ + "migrations/sql/cockroach/9.sql": migrationsSqlCockroach9Sql, "migrations/sql/mysql/.gitkeep": migrationsSqlMysqlGitkeep, "migrations/sql/mysql/5.sql": migrationsSqlMysql5Sql, "migrations/sql/mysql/6.sql": migrationsSqlMysql6Sql, @@ -712,6 +734,9 @@ type bintree struct { var _bintree = &bintree{nil, map[string]*bintree{ "migrations": &bintree{nil, map[string]*bintree{ "sql": &bintree{nil, map[string]*bintree{ + "cockroach": &bintree{nil, map[string]*bintree{ + "9.sql": &bintree{migrationsSqlCockroach9Sql, map[string]*bintree{}}, + }}, "mysql": &bintree{nil, map[string]*bintree{ ".gitkeep": &bintree{migrationsSqlMysqlGitkeep, map[string]*bintree{}}, "5.sql": &bintree{migrationsSqlMysql5Sql, map[string]*bintree{}}, diff --git a/oauth2/x_fosite_migrations_test.go b/oauth2/x_fosite_migrations_test.go index 61a8bf1e4cd..c51d671bd65 100644 --- a/oauth2/x_fosite_migrations_test.go +++ b/oauth2/x_fosite_migrations_test.go @@ -5,27 +5,19 @@ import ( "fmt" "testing" - "github.com/ory/hydra/x" - "github.com/jmoiron/sqlx" - "github.com/sirupsen/logrus" "github.com/stretchr/testify/require" - "github.com/ory/hydra/internal" - "github.com/ory/fosite" "github.com/ory/hydra/client" "github.com/ory/hydra/consent" + "github.com/ory/hydra/internal" "github.com/ory/hydra/oauth2" + "github.com/ory/hydra/x" "github.com/ory/x/dbal" "github.com/ory/x/dbal/migratest" ) -var createMigrations = map[string]*dbal.PackrMigrationSource{ - dbal.DriverMySQL: dbal.NewMustPackerMigrationSource(logrus.New(), oauth2.AssetNames(), oauth2.Asset, []string{"migrations/sql/tests"}, true), - dbal.DriverPostgreSQL: dbal.NewMustPackerMigrationSource(logrus.New(), oauth2.AssetNames(), oauth2.Asset, []string{"migrations/sql/tests"}, true), -} - func TestXXMigrations(t *testing.T) { if testing.Short() { t.SkipNow() @@ -35,10 +27,10 @@ func TestXXMigrations(t *testing.T) { migratest.RunPackrMigrationTests( t, migratest.MigrationSchemas{client.Migrations, consent.Migrations, oauth2.Migrations}, - migratest.MigrationSchemas{nil, nil, createMigrations}, + migratest.MigrationSchemas{nil, nil, dbal.FindMatchingTestMigrations("migrations/sql/tests/", oauth2.Migrations, oauth2.AssetNames(), oauth2.Asset)}, x.CleanSQL, x.CleanSQL, - func(t *testing.T, db *sqlx.DB, m, k, steps int) { + func(t *testing.T, dbName string, db *sqlx.DB, m, k, steps int) { t.Run(fmt.Sprintf("poll=%d", k), func(t *testing.T) { conf := internal.NewConfigurationWithDefaults() reg := internal.NewRegistrySQL(conf, db) @@ -49,6 +41,9 @@ func TestXXMigrations(t *testing.T) { } s := reg.OAuth2Storage().(*oauth2.FositeSQLStore) + if dbName == "cockroach" { + k += 8 + } sig := fmt.Sprintf("%d-sig", k+1) if k < 8 { @@ -57,7 +52,6 @@ func TestXXMigrations(t *testing.T) { require.Error(t, err) return } - _, err := s.GetAccessTokenSession(context.Background(), sig, oauth2.NewSession("")) require.NoError(t, err) _, err = s.GetRefreshTokenSession(context.Background(), sig, oauth2.NewSession("")) diff --git a/quickstart-cockroach.yml b/quickstart-cockroach.yml new file mode 100644 index 00000000000..efd45c3c3d2 --- /dev/null +++ b/quickstart-cockroach.yml @@ -0,0 +1,36 @@ +########################################################################### +####### FOR DEMONSTRATION PURPOSES ONLY ####### +########################################################################### +# # +# If you have not yet read the tutorial, do so now: # +# https://www.ory.sh/docs/hydra/5min-tutorial # +# # +# This set up is only for demonstration purposes. The login # +# endpoint can only be used if you follow the steps in the tutorial. # +# # +########################################################################### + +version: '3' + +services: + + hydra-migrate: + image: oryd/hydra:latest + environment: + - DSN=cockroach://root@cockroachd:26257/defaultdb?sslmode=disable&max_conns=20&max_idle_conns=4 + command: + migrate sql -e --yes + restart: on-failure + + hydra: + depends_on: + - hydra-migrate + environment: + - DSN=cockroach://root@cockroachd:26257/defaultdb?sslmode=disable&max_conns=20&max_idle_conns=4 + restart: unless-stopped + + cockroachd: + image: cockroachdb/cockroach:v2.1.6 + ports: + - "26257:26257" + command: start --insecure diff --git a/scripts/run-bench.sh b/scripts/run-bench.sh index 8e6e6a52ca5..e6067eb28fe 100755 --- a/scripts/run-bench.sh +++ b/scripts/run-bench.sh @@ -20,7 +20,7 @@ In this document you will find benchmark results for different endpoints of ORY using [rakyll/hey](https://github.com/rakyll/hey). Please note that these benchmarks run against the in-memory storage adapter of ORY Hydra. These benchmarks represent what performance you would get with a zero-overhead database implementation. -We do not include benchmarks against databases (e.g. MySQL or PostgreSQL) as the performance greatly differs between +We do not include benchmarks against databases (e.g. MySQL, PostgreSQL or CockroachDB) as the performance greatly differs between deployments (e.g. request latency, database configuration) and tweaking individual things may greatly improve performance. We believe, for that reason, that benchmark results for these database adapters are difficult to generalize and potentially deceiving. They are thus not included. diff --git a/test/e2e/circle-ci.bash b/test/e2e/circle-ci.bash index bbf9648a785..ff9d125773c 100755 --- a/test/e2e/circle-ci.bash +++ b/test/e2e/circle-ci.bash @@ -73,6 +73,22 @@ case "$1" in export CYPRESS_jwt_enabled=true ;; + cockroach) + hydra migrate sql --yes $TEST_DATABASE_COCKROACHDB + DSN=$TEST_DATABASE_COCKROACHDB \ + hydra serve all --dangerous-force-http --disable-telemetry >> ./hydra.e2e.log 2>&1 & + export CYPRESS_jwt_enabled=false + ;; + + cockroach-jwt) + hydra migrate sql --yes $TEST_DATABASE_COCKROACHDB + DSN=$TEST_DATABASE_COCKROACHDB \ + OAUTH2_ACCESS_TOKEN_STRATEGY=jwt \ + OIDC_SUBJECT_IDENTIFIERS_ENABLED=public \ + hydra serve all --dangerous-force-http --disable-telemetry >> ./hydra.e2e.log 2>&1 & + export CYPRESS_jwt_enabled=true + ;; + plugin) DSN=plugin://./memtest.so \ hydra serve all --dangerous-force-http --disable-telemetry >> ./hydra.e2e.log 2>&1 & @@ -87,7 +103,7 @@ case "$1" in export CYPRESS_jwt_enabled=true ;; *) - echo $"Usage: $0 {memory|postgres|mysql|plugin|memory-jwt|postgres-jwt|mysql-jwt|plugin-jwt} [--watch]" + echo $"Usage: $0 {memory|postgres|mysql|cockroach|plugin|memory-jwt|postgres-jwt|mysql-jwt|cockroach-jwt|plugin-jwt} [--watch]" exit 1 esac diff --git a/test/e2e/docker-compose.cockroach.yml b/test/e2e/docker-compose.cockroach.yml new file mode 100644 index 00000000000..157651a6da9 --- /dev/null +++ b/test/e2e/docker-compose.cockroach.yml @@ -0,0 +1,23 @@ +version: '3' + +services: + + hydra-migrate: + image: oryd/hydra:e2e + environment: + - DSN=cockroach://root@cockroachd:26257/defaultdb?sslmode=disable&max_conns=20&max_idle_conns=4 + command: + migrate sql -e --yes + restart: on-failure + + hydra: + depends_on: + - hydra-migrate + environment: + - DSN=cockroach://root@cockroachd:26257/defaultdb?sslmode=disable&max_conns=20&max_idle_conns=4 + + cockroachd: + image: cockroachdb/cockroach:v2.1.6 + ports: + - "26257:26257" + command: start --insecure diff --git a/test/mock-client/main.go b/test/mock-client/main.go index 7194b561a82..4a918dce391 100644 --- a/test/mock-client/main.go +++ b/test/mock-client/main.go @@ -34,14 +34,13 @@ import ( "strings" "time" - "github.com/ory/hydra/sdk/go/hydra/client/admin" - "github.com/ory/x/urlx" - "github.com/dgrijalva/jwt-go" "golang.org/x/oauth2" hydra "github.com/ory/hydra/sdk/go/hydra/client" + "github.com/ory/hydra/sdk/go/hydra/client/admin" "github.com/ory/x/cmdx" + "github.com/ory/x/urlx" ) var hydraURL = urlx.ParseOrPanic(os.Getenv("HYDRA_ADMIN_URL"))