-
Notifications
You must be signed in to change notification settings - Fork 15
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 #29 from alanenriqueo/fix-public-ip-firewall
Add support for flexible server and obtain runner's public IP address from ipify
- Loading branch information
Showing
11 changed files
with
330 additions
and
90 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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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 |
---|---|---|
@@ -1,42 +1,35 @@ | ||
import PsqlUtils from "../../Utils/PsqlUtils/PsqlUtils"; | ||
import { FirewallConstants } from "../../Constants"; | ||
import { HttpClient } from '@actions/http-client'; | ||
import PsqlToolRunner from "../../Utils/PsqlUtils/PsqlToolRunner"; | ||
import PsqlUtils, { IPResponse } from "../../Utils/PsqlUtils/PsqlUtils"; | ||
|
||
jest.mock('../../Utils/PsqlUtils/PsqlToolRunner'); | ||
const CONFIGURED = "configured"; | ||
jest.mock('@actions/http-client'); | ||
|
||
describe('Testing PsqlUtils', () => { | ||
afterEach(() => { | ||
jest.clearAllMocks() | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
let detectIPAddressSpy: any; | ||
beforeAll(() => { | ||
detectIPAddressSpy = PsqlUtils.detectIPAddress = jest.fn().mockImplementation( (connString: string) => { | ||
let psqlError; | ||
if (connString != CONFIGURED) { | ||
psqlError = `psql: error: could not connect to server: FATAL: no pg_hba.conf entry for host "1.2.3.4", user "<user>", database "<db>"`; | ||
} | ||
let ipAddress = ''; | ||
if (psqlError) { | ||
const ipAddresses = psqlError.match(FirewallConstants.ipv4MatchPattern); | ||
if (ipAddresses) { | ||
ipAddress = ipAddresses[0]; | ||
} else { | ||
throw new Error(`Unable to detect client IP Address: ${psqlError}`); | ||
} | ||
} | ||
return ipAddress; | ||
test('detectIPAddress should return ip address', async () => { | ||
const psqlError: string = `psql: error: could not connect to server: FATAL: no pg_hba.conf entry for host "1.2.3.4", user "<user>", database "<db>"`; | ||
|
||
jest.spyOn(PsqlToolRunner, 'executePsqlCommand').mockImplementation(async (_connectionString: string, _command: string, options: any = {}) => { | ||
options.listeners.stderr(Buffer.from(psqlError)); | ||
throw new Error(psqlError); | ||
}); | ||
jest.spyOn(HttpClient.prototype, 'getJson').mockResolvedValue({ | ||
statusCode: 200, | ||
result: { | ||
ip: '1.2.3.4', | ||
}, | ||
headers: {}, | ||
}); | ||
}); | ||
|
||
test('detectIPAddress should return ip address', async () => { | ||
await PsqlUtils.detectIPAddress(""); | ||
expect(detectIPAddressSpy).toReturnWith("1.2.3.4"); | ||
return PsqlUtils.detectIPAddress("").then(ipAddress => expect(ipAddress).toEqual("1.2.3.4")); | ||
}); | ||
|
||
test('detectIPAddress should return empty string', async () => { | ||
await PsqlUtils.detectIPAddress(CONFIGURED); | ||
expect(detectIPAddressSpy).toReturnWith(""); | ||
return PsqlUtils.detectIPAddress("").then(ipAddress => expect(ipAddress).toEqual("")); | ||
}) | ||
|
||
}); |
Oops, something went wrong.