-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1778 from christianvogt/no-scheme
Fix error creating pipeline server when data connection endpoint omits scheme
- Loading branch information
Showing
3 changed files
with
148 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
frontend/src/concepts/pipelines/content/configurePipelinesServer/__tests__/utils.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
import { AWS_KEYS } from '~/pages/projects/dataConnections/const'; | ||
import { PipelineServerConfigType } from '~/concepts/pipelines/content/configurePipelinesServer/types'; | ||
import { createDSPipelineResourceSpec } from '~/concepts/pipelines/content/configurePipelinesServer/utils'; | ||
|
||
describe('configure pipeline server utils', () => { | ||
describe('createDSPipelineResourceSpec', () => { | ||
const createPipelineServerConfig = () => | ||
({ | ||
database: { | ||
useDefault: true, | ||
value: [], | ||
}, | ||
objectStorage: { | ||
useExisting: true, | ||
existingName: '', | ||
existingValue: [], | ||
}, | ||
} as PipelineServerConfigType); | ||
|
||
type SecretsResponse = Parameters<typeof createDSPipelineResourceSpec>[1]; | ||
|
||
const createSecretsResponse = ( | ||
databaseSecret?: SecretsResponse[0], | ||
objectStorageSecret?: SecretsResponse[1], | ||
): SecretsResponse => [databaseSecret, objectStorageSecret ?? { secretName: '', awsData: [] }]; | ||
|
||
it('should create resource spec', () => { | ||
const spec = createDSPipelineResourceSpec( | ||
createPipelineServerConfig(), | ||
createSecretsResponse(), | ||
); | ||
expect(spec).toEqual({ | ||
database: undefined, | ||
objectStorage: { | ||
externalStorage: { | ||
bucket: '', | ||
host: '', | ||
s3CredentialsSecret: { | ||
accessKey: 'AWS_ACCESS_KEY_ID', | ||
secretKey: 'AWS_SECRET_ACCESS_KEY', | ||
secretName: '', | ||
}, | ||
scheme: 'https', | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should parse S3 endpoint with scheme', () => { | ||
const secretsResponse = createSecretsResponse(); | ||
secretsResponse[1].awsData = [ | ||
{ key: AWS_KEYS.S3_ENDPOINT, value: 'http://s3.amazonaws.com' }, | ||
]; | ||
const spec = createDSPipelineResourceSpec(createPipelineServerConfig(), secretsResponse); | ||
expect(spec.objectStorage.externalStorage?.scheme).toBe('http'); | ||
expect(spec.objectStorage.externalStorage?.host).toBe('s3.amazonaws.com'); | ||
}); | ||
|
||
it('should parse S3 endpoint without scheme', () => { | ||
const secretsResponse = createSecretsResponse(); | ||
|
||
secretsResponse[1].awsData = [{ key: AWS_KEYS.S3_ENDPOINT, value: 's3.amazonaws.com' }]; | ||
const spec = createDSPipelineResourceSpec(createPipelineServerConfig(), secretsResponse); | ||
expect(spec.objectStorage.externalStorage?.scheme).toBe('https'); | ||
expect(spec.objectStorage.externalStorage?.host).toBe('s3.amazonaws.com'); | ||
}); | ||
|
||
it('should include bucket', () => { | ||
const secretsResponse = createSecretsResponse(); | ||
secretsResponse[1].awsData = [{ key: AWS_KEYS.AWS_S3_BUCKET, value: 'my-bucket' }]; | ||
const spec = createDSPipelineResourceSpec(createPipelineServerConfig(), secretsResponse); | ||
expect(spec.objectStorage.externalStorage?.bucket).toBe('my-bucket'); | ||
}); | ||
|
||
it('should create spec with database object', () => { | ||
const config = createPipelineServerConfig(); | ||
config.database.value = [ | ||
{ | ||
key: 'Username', | ||
value: 'test-user', | ||
}, | ||
{ | ||
key: 'Port', | ||
value: '8080', | ||
}, | ||
{ | ||
key: 'Host', | ||
value: 'test.host.com', | ||
}, | ||
{ | ||
key: 'Database', | ||
value: 'db-name', | ||
}, | ||
]; | ||
const spec = createDSPipelineResourceSpec( | ||
config, | ||
createSecretsResponse({ | ||
key: 'password-key', | ||
name: 'password-name', | ||
}), | ||
); | ||
expect(spec).toEqual({ | ||
objectStorage: { | ||
externalStorage: { | ||
bucket: '', | ||
host: '', | ||
s3CredentialsSecret: { | ||
accessKey: 'AWS_ACCESS_KEY_ID', | ||
secretKey: 'AWS_SECRET_ACCESS_KEY', | ||
secretName: '', | ||
}, | ||
scheme: 'https', | ||
}, | ||
}, | ||
database: { | ||
externalDB: { | ||
host: 'test.host.com', | ||
passwordSecret: { | ||
key: 'password-key', | ||
name: 'password-name', | ||
}, | ||
pipelineDBName: 'db-name', | ||
port: '8080', | ||
username: 'test-user', | ||
}, | ||
}, | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters