Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion runtime-light/stdlib/system/system-functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ inline Optional<array<mixed>> f$posix_getpwuid(int64_t user_id) noexcept {

array<mixed> result{array_size{7, false}};
result.set_value(string{kphp::posix::impl::NAME_PWUID_KEY.data(), kphp::posix::impl::NAME_PWUID_KEY.size()}, string{pwd.pw_name});
result.set_value(string{kphp::posix::impl::PASSWD_PWUID_KEY.data(), kphp::posix::impl::NAME_PWUID_KEY.size()}, string{pwd.pw_passwd});
result.set_value(string{kphp::posix::impl::PASSWD_PWUID_KEY.data(), kphp::posix::impl::PASSWD_PWUID_KEY.size()}, string{pwd.pw_passwd});
result.set_value(string{kphp::posix::impl::UID_PWUID_KEY.data(), kphp::posix::impl::UID_PWUID_KEY.size()}, static_cast<int64_t>(pwd.pw_uid));
result.set_value(string{kphp::posix::impl::GID_PWUID_KEY.data(), kphp::posix::impl::GID_PWUID_KEY.size()}, static_cast<int64_t>(pwd.pw_gid));
result.set_value(string{kphp::posix::impl::GECOS_PWUID_KEY.data(), kphp::posix::impl::GECOS_PWUID_KEY.size()}, string{pwd.pw_gecos});
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
entry: script
components:
script:
image: KPHP
scope: Request
args: {}
links: {}
38 changes: 38 additions & 0 deletions tests/python/tests/system_function/php/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

function test_posix_getpid() {
echo json_encode(array(
"pid" => posix_getpid()
));
}

function test_posix_getuid() {
echo json_encode(array(
"uid" => posix_getuid()
));
}

function test_posix_getpwuid() {
echo json_encode(posix_getpwuid(posix_getuid()));
}

function main() {
switch ($_SERVER["PHP_SELF"]) {
case "/test_posix_getpid": {
test_posix_getpid();
return;
}
case "/test_posix_getuid": {
test_posix_getuid();
return;
}
case "/test_posix_getpwuid": {
test_posix_getpwuid();
return;
}
}

critical_error("unknown test");
}

main();
43 changes: 43 additions & 0 deletions tests/python/tests/system_function/test_posix_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import json
import os
import pwd
import typing
from python.lib.testcase import WebServerAutoTestCase
from python.lib.kphp_server import KphpServer

class TestErrors(WebServerAutoTestCase):
@classmethod
def extra_class_setup(cls):
if not cls.should_use_k2():
cls.web_server.update_options({
"--workers-num": 1
})

def test_posix_getpid(self):
pid = 0
if isinstance(self.web_server, KphpServer):
pid = typing.cast(KphpServer, self.web_server).get_workers()[0].pid
else:
pid = self.web_server.pid

response = self.web_server.http_request(uri="/test_posix_getpid", method='GET')
self.assertEqual(pid, json.loads(response.text)["pid"])
self.assertEqual(200, response.status_code)

def test_posix_getuid(self):
response = self.web_server.http_request(uri="/test_posix_getuid", method='GET')
self.assertEqual(os.getuid(), json.loads(response.text)["uid"])
self.assertEqual(200, response.status_code)

def test_posix_getpwuid(self):
response = self.web_server.http_request(uri="/test_posix_getpwuid", method='GET')
expected = pwd.getpwuid(os.getuid())
got = json.loads(response.text)
self.assertEqual(expected[0], got['name'])
self.assertEqual(expected[1], got['passwd'])
self.assertEqual(expected[2], got['uid'])
self.assertEqual(expected[3], got['gid'])
self.assertEqual(expected[4], got['gecos'])
self.assertEqual(expected[5], got['dir'])
self.assertEqual(expected[6], got['shell'])
self.assertEqual(200, response.status_code)
Loading