Skip to content

Commit

Permalink
fix: make sure process.getuid doesn't get called on Windows
Browse files Browse the repository at this point in the history
`process.getuid` method isn't supported on `Windows` as explained [here](https://nodejs.org/api/process.html#process_process_getuid); so, this commit is for fixing that bug.

Ref: LOG-6981
Semver: patch

fix: make sure  doesn't get called on
  • Loading branch information
Samir Musali committed Aug 21, 2020
1 parent 45964da commit 594133f
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ lib-cov

# Coverage directory used by tools like istanbul
coverage
.nyc_output

# node-waf configuration
.lock-wscript
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Fix stringification issue on handling 207 [#152](https://github.com/logdna/logdna-agent/pull/152)
- Fix memory leak issue [#157](https://github.com/logdna/logdna-agent/pull/157)
- Make sure `process.getuid` doesn't get called on `Windows` [#188](https://github.com/logdna/logdna-agent/pull/188)

## [1.6.2] - December 5, 2019
### Added
Expand Down
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ commander
console.log()
})

function loadConfig(program, uid) {
if ((os.platform() === 'win32' && require('is-administrator')()) || uid <= 0) {
function loadConfig(program, isAdmin) {
if (isAdmin) {
const conf_file = program.config || config.DEFAULT_CONF_FILE
debug(`Path to Configuration File: ${conf_file}`)
async.waterfall([
Expand Down Expand Up @@ -307,7 +307,7 @@ process.on('uncaughtException', err => utils.log(`uncaught error: ${(err.stack |

if (require.main === module) {
commander.parse(process.argv)
loadConfig(commander, process.getuid())
loadConfig(commander, os.platform() === 'win32' ? require('is-administrator')() : process.getuid() === 0)
}

module.exports = {
Expand Down
18 changes: 9 additions & 9 deletions test/unit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const fs = require('fs')
const {test} = require('tap')
const {loadConfig, commander} = require('../../index.js')

const uid = 0
const isAdmin = true

test('Commander help output', (t) => {
commander.outputHelp((help) => {
Expand All @@ -23,7 +23,7 @@ test('loadConfig() settings based on user input', async (t) => {
t.test('Errors if no key is found', (tt) => {
loadConfig({
config: configFile
}, uid)
}, isAdmin)

setTimeout(() => {
fs.stat(configFile, (err) => {
Expand All @@ -42,7 +42,7 @@ test('loadConfig() settings based on user input', async (t) => {
, hostname: 'myMachine'
}

loadConfig(input, uid)
loadConfig(input, isAdmin)

// The callback is not exposed. We have to wait for the file to be written to.
setTimeout(() => {
Expand All @@ -64,7 +64,7 @@ test('loadConfig() settings based on user input', async (t) => {
, logdir: logs
}

loadConfig(input, uid)
loadConfig(input, isAdmin)

setTimeout(() => {
const contents = (fs.readFileSync(configFile, 'utf8')).split('\n').sort()
Expand All @@ -91,7 +91,7 @@ test('loadConfig() settings based on user input', async (t) => {
, tags
}

loadConfig(input, uid)
loadConfig(input, isAdmin)

setTimeout(() => {
const contents = (fs.readFileSync(configFile, 'utf8')).split('\n')
Expand Down Expand Up @@ -128,7 +128,7 @@ test('loadConfig() settings based on user input', async (t) => {
loadConfig({
config: configFile
, unset: ['set1']
}, uid)
}, isAdmin)

setTimeout(() => {
const contents = (fs.readFileSync(configFile, 'utf8')).split('\n')
Expand All @@ -148,7 +148,7 @@ test('loadConfig() settings based on user input', async (t) => {
loadConfig({
config: configFile
, unset: ['all']
}, uid)
}, isAdmin)

setTimeout(() => {
const contents = (fs.readFileSync(configFile, 'utf8'))
Expand All @@ -167,7 +167,7 @@ test('loadConfig() hostname decisions', async (t) => {
, key: 'abc123'
}

loadConfig(input, uid)
loadConfig(input, isAdmin)

// The callback is not exposed. We have to wait for the file to be written to.
setTimeout(() => {
Expand Down Expand Up @@ -211,7 +211,7 @@ test('Process options through commander', (t) => {
]

commander.parse(input)
loadConfig(commander, uid)
loadConfig(commander, isAdmin)

setTimeout(() => {
const contents = (fs.readFileSync(configFile, 'utf8')).split('\n').sort()
Expand Down
4 changes: 0 additions & 4 deletions tools/files/win32/logdna-agent.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
<authors>smusali,leeliu</authors>
<owners>leeliu</owners>
<summary>LogDNA Agent for Windows</summary>
<version>1.6.3</version>
<authors>smusali,leeliu</authors>
<owners>leeliu</owners>
<summary>LogDNA Agent for Windows</summary>
<description>LogDNA Collector Agent Streaming File and Event Logs to LogDNA.</description>
<projectUrl>https://logdna.com/</projectUrl>
<projectSourceUrl>https://github.com/logdna/logdna-agent</projectSourceUrl>
Expand Down
3 changes: 2 additions & 1 deletion tools/scripts/darwin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ cd ../.pkg
mv ../.build/logdna-agent-${VERSION}.pkg logdna-agent-${VERSION}-unsigned.pkg
productsign --sign "Developer ID Installer: Answerbook, Inc. (TT7664HMU3)" logdna-agent-${VERSION}-unsigned.pkg logdna-agent-${VERSION}.pkg
SHA256CHECKSUM=$(shasum -a 256 logdna-agent-${VERSION}.pkg | cut -d' ' -f1)
sed "s/$(cat ../tools/files/darwin/logdna-agent.rb | grep sha256 | cut -d"'" -f2)/${SHA256CHECKSUM}/" ../tools/files/darwin/logdna-agent.rb > logdna-agent.rb
OLDSHA256CHECKSUM=$(cat ../tools/files/darwin/logdna-agent.rb | grep sha256 | cut -d"'" -f2)
sed "s/${OLDSHA256CHECKSUM}/${SHA256CHECKSUM}/" ../tools/files/darwin/logdna-agent.rb > logdna-agent.rb
cd ..

# STEP 4: RELEASE
Expand Down
5 changes: 3 additions & 2 deletions tools/scripts/win32.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ nexe -i index.js -o .build/tools/${PACKAGE_NAME}.exe -t win32-${ARCH}-${NODE_VER

# STEP 2: PACKAGE
cd .build/
sed -i "s/latest/${VERSION}/" tools/VERIFICATION.txt
sed "s/latest/${VERSION}/" ./tools/VERIFICATION.txt > ./tools/VERIFICATION.txt
SHA256CHECKSUM=$(shasum -a 256 tools/${PACKAGE_NAME}.exe | cut -d' ' -f1)
sed -i "s/$(cat tools/VERIFICATION.txt | grep 'checksum: ' | cut -d' ' -f4)/${SHA256CHECKSUM}/" tools/VERIFICATION.txt
OLDSHA256CHECKSUM=$(cat tools/VERIFICATION.txt | grep 'checksum: ' | cut -d' ' -f4)
sed "s/${OLDSHA256CHECKSUM}/${SHA256CHECKSUM}/" ./tools/VERIFICATION.txt > ./tools/VERIFICATION.txt
choco pack logdna-agent.nuspec
cd ..
cp .build/*.nupkg .build/tools/*.exe .pkg/
Expand Down

0 comments on commit 594133f

Please sign in to comment.