Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
1dc3e5a
Add comment for developers
mtompset Mar 12, 2025
83402f0
Revise doesUserMatch() to reduce complexity
mtompset Mar 12, 2025
dc0b022
Update dependencies and prepare version for release
mtompset Mar 12, 2025
6944ddc
Remove extraneous parenthesis on return statements
mtompset Mar 12, 2025
301ac39
Replace hard coded string with constant
mtompset Mar 12, 2025
6e676c1
Use assertEquals not assertTrue
mtompset Mar 12, 2025
f02cde7
Use assertSame, not assertEquals
mtompset Mar 12, 2025
648a98e
Create specific exceptions
mtompset Mar 12, 2025
0c74dbb
Add missing newline
mtompset Mar 12, 2025
55bd1ba
Add exception for GroupSettings not existing
mtompset Mar 12, 2025
362e81e
Intentionally exclude recommends, but not necessary dependencies
mtompset Mar 12, 2025
d721c8e
Attempt to not use root
mtompset Mar 12, 2025
d116eef
Add a non-root user line at the top
mtompset Mar 12, 2025
3e7309e
Make the nonroot user explicitly
mtompset Mar 13, 2025
227f7f2
Avoid complete recursive copy
mtompset Mar 13, 2025
962bf61
Specifically decide what to copy from the root directory
mtompset Mar 13, 2025
3fc4a6e
Dockerfile layering clean ups
mtompset Mar 13, 2025
b5b4fc6
Make sure the development test databases exist and are writable
mtompset Mar 25, 2025
cec69c5
Address failures in GitHub actions testing
mtompset Mar 25, 2025
0761caf
Make sure test data files are owned and have writable permissions
mtompset Mar 25, 2025
66b6e56
Make sure everything is owned by nonroot:root to improve writability …
mtompset Mar 25, 2025
8b7a107
Remove unused variable as the return value isn't checked
mtompset Mar 25, 2025
ff72216
Installing composer needs root, but running composer does not
mtompset Mar 25, 2025
61866e6
Merge the two runs together
mtompset Mar 25, 2025
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
46 changes: 39 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,28 +1,60 @@
FROM php:8.2-apache
RUN useradd nonroot
LABEL maintainer="Mark Tompsett <mark_tompsett@sil.org>"

ENV REFRESHED_AT 2023-07-12

# Make sure apt has current list/updates
USER root
RUN apt-get update -y \
# Fix timezone stuff from hanging.
&& echo "America/New_York" > /etc/timezone \
&& apt-get install -y tzdata \
&& apt-get install -y --no-install-recommends tzdata \
&& apt-get upgrade -y \
# Install
&& apt-get install -y \
&& apt-get install -y --no-install-recommends \
# things needed for GoogleMock objects
sqlite3 \
# some basics
unzip wget zip \
# Clean up to reduce docker image size
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
&& rm -rf /var/lib/apt/lists/* \
# Make sure the directory we'll mount and reference is there
&& mkdir -p /data

RUN mkdir -p /data
USER nonroot
WORKDIR /data
COPY ./ /data
COPY actions-services.yml /data
COPY composer-install.sh /data
COPY composer.json /data
COPY composer.lock /data
COPY docker-compose.yml /data
COPY Dockerfile /data
COPY LICENSE /data
COPY Makefile /data
COPY README.md /data
COPY run-tests.sh /data
COPY .travis.yml /data
COPY SilMock/ /data/SilMock

RUN cd /data && ./composer-install.sh
RUN mv /data/composer.phar /usr/bin/composer
USER root
# Make sure the development test files exist and have writable permissions
RUN touch /data/SilMock/DataStore/Sqlite/Test1_Google_Service_Data.db && \
touch /data/SilMock/DataStore/Sqlite/Test2_Google_Service_Data.db && \
touch /data/SilMock/DataStore/Sqlite/Test3_Google_Service_Data.db && \
touch /data/SilMock/DataStore/Sqlite/Test4_Google_Service_Data.db && \
touch /data/SilMock/DataStore/Sqlite/Test5_Google_Service_Data.db && \
touch /data/SilMock/tests/.phpunit.result.cache && \
chown -R nonroot:root /data && \
chmod 664 /data/SilMock/DataStore/Sqlite/Test1_Google_Service_Data.db && \
chmod 664 /data/SilMock/DataStore/Sqlite/Test2_Google_Service_Data.db && \
chmod 664 /data/SilMock/DataStore/Sqlite/Test3_Google_Service_Data.db && \
chmod 664 /data/SilMock/DataStore/Sqlite/Test4_Google_Service_Data.db && \
chmod 664 /data/SilMock/DataStore/Sqlite/Test5_Google_Service_Data.db && \
chmod 664 /data/SilMock/tests/.phpunit.result.cache

WORKDIR /data
RUN ./composer-install.sh && mv /data/composer.phar /usr/bin/composer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If at some point you want to simplify this (to possibly get rid of the need for a composer-install.sh script), you can also just copy the composer binary from their Docker image, like so:

COPY --from=composer:2 /usr/bin/composer /usr/local/bin/composer

You can use whatever version tag you want to, after the colon in that --from parameter.

USER nonroot
RUN /usr/bin/composer install
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,5 @@ Examples

$aliases = $dir->users_aliases->listUsersAliases($users_email);
$alias = $dir->users_aliases->delete($users_email, $alias);

### DEVELOPER'S NOTE: Releases should include updating the version in composer.json to match
6 changes: 4 additions & 2 deletions SilMock/Google/Service/Directory/Resource/Groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Google\Service\Directory\Groups as GoogleDirectory_Groups;
use Google\Service\Directory\Alias as GoogleDirectory_GroupAlias;
use Google\Service\Groupssettings\Groups as GoogleGroupsSettings_Group;
use SilMock\exceptions\GroupAlreadyExistsException;
use SilMock\exceptions\GroupDoesNotExistException;
use SilMock\Google\Service\DbClass;
use SilMock\Google\Service\Directory\ObjectUtils;
use SilMock\Google\Service\Groupssettings\Resource\Groups as MockGroupssettings_ResourceGroups;
Expand Down Expand Up @@ -92,7 +94,7 @@ public function insert(GoogleDirectory_Group $postBody, $optParams = [])
$groupSettings->setWhoCanViewGroup('ALL_MEMBERS_CAN_VIEW');
$mockGroupSettings->insert($groupSettings);
} else {
throw new Exception(
throw new GroupAlreadyExistsException(
"Cannot group.insert an existing group: " . $postBody->getEmail()
);
}
Expand Down Expand Up @@ -166,7 +168,7 @@ protected function isNewGroup(string $groupKey): bool
public function update(string $groupKey, GoogleDirectory_Group $postBody, $optParams = []): GoogleDirectory_Group
{
if ($this->isNewGroup($postBody->getEmail())) {
throw new Exception("Group '{$groupKey}' does not exist.");
throw new GroupDoesNotExistException("Group '{$groupKey}' does not exist.");
}
$group = $this->get($groupKey);

Expand Down
8 changes: 2 additions & 6 deletions SilMock/Google/Service/Directory/UsersResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ public function update($userKey, $postBody)
$newAlias->kind = "personal";
$newAlias->primaryEmail = $postBody->primaryEmail;

$insertedAlias = $usersAliases->insertAssumingUserExists($newAlias);
$usersAliases->insertAssumingUserExists($newAlias);
}
}

Expand Down Expand Up @@ -451,10 +451,6 @@ private function doesUserMatch($entry, $query = '')
)
);
}
if (mb_strpos($checkValue, $value) === 0) {
return true;
} else {
return false;
}
return mb_strpos($checkValue, $value) === 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ protected function assertIsValidDelegateEmail($delegateEmail)
*/
protected function isValidEmailAddress($email)
{
return (filter_var($email, FILTER_VALIDATE_EMAIL) !== false);
return filter_var($email, FILTER_VALIDATE_EMAIL) !== false;
}

public function get($userId, $delegateEmail, $optParams = array())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected function assertIsValidDelegateEmail($delegateEmail)
*/
protected function isValidEmailAddress(string $email): bool
{
return (filter_var($email, FILTER_VALIDATE_EMAIL) !== false);
return filter_var($email, FILTER_VALIDATE_EMAIL) !== false;
}

/**
Expand Down
5 changes: 3 additions & 2 deletions SilMock/Google/Service/Groupssettings/Resource/Groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Exception;
use Google\Service\Groupssettings\Groups as GoogleGroupsSettings_Groups;
use SilMock\exceptions\GroupSettingsDoNotExistException;
use SilMock\Google\Service\DbClass;
use SilMock\Google\Service\Directory\ObjectUtils;

Expand Down Expand Up @@ -35,7 +36,7 @@ public function delete(string $groupKey)
protected function doGroupsSettingsExist(string $groupKey): bool
{
$groupsSettings = $this->get($groupKey);
return ($groupsSettings !== null);
return $groupsSettings !== null;
}

public function get(string $groupKey): ?GoogleGroupsSettings_Groups
Expand Down Expand Up @@ -79,7 +80,7 @@ public function update(
$optParams = []
): GoogleGroupsSettings_Groups {
if (! $this->doGroupsSettingsExist($postBody->getEmail())) {
throw new Exception("Group Settings for '{$groupKey}' does not exist.");
throw new GroupSettingsDoNotExistException("Group Settings for '{$groupKey}' does not exist.");
}
$groupsSettings = $this->get($groupKey);

Expand Down
9 changes: 9 additions & 0 deletions SilMock/exceptions/GroupAlreadyExistsException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace SilMock\exceptions;

use Exception;

class GroupAlreadyExistsException extends Exception
{
}
9 changes: 9 additions & 0 deletions SilMock/exceptions/GroupDoesNotExistException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace SilMock\exceptions;

use Exception;

class GroupDoesNotExistException extends Exception
{
}
9 changes: 9 additions & 0 deletions SilMock/exceptions/GroupSettingsDoNotExistException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace SilMock\exceptions;

use Exception;

class GroupSettingsDoNotExistException extends Exception
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class GroupsTest extends TestCase
public string $dataFile = DATAFILE5;
public const GROUP_EMAIL_ADDRESS = 'sample_group@example.com';
public const GROUP_ALIAS_ADDRESS = 'ma_org_sample_group@groups.example.com';
public const GROUP_INSERT_FAILURE_TEMPLATE = 'Was expecting the groups.insert method to function, but got: %s';

protected function deleteGroupAndAliasesIfTheyExists(string $groupName)
{
Expand Down Expand Up @@ -45,7 +46,7 @@ public function testInsert()
} catch (Exception $exception) {
self::fail(
sprintf(
'Was expecting the groups.insert method to function, but got: %s',
self::GROUP_INSERT_FAILURE_TEMPLATE,
$exception->getMessage()
)
);
Expand All @@ -71,7 +72,7 @@ public function testUpdate()
} catch (Exception $exception) {
self::fail(
sprintf(
'Was expecting the groups.insert method to function, but got: %s',
self::GROUP_INSERT_FAILURE_TEMPLATE,
$exception->getMessage()
)
);
Expand Down Expand Up @@ -104,7 +105,7 @@ protected function deleteTestSetup()
} catch (Exception $exception) {
self::fail(
sprintf(
'Was expecting the groups.insert method to function, but got: %s',
self::GROUP_INSERT_FAILURE_TEMPLATE,
$exception->getMessage()
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ public function testGet()
$mockGroupsSettings = new MockGroupsSettings_ResourceGroups($this->dataFile);
$groupsSettings = $mockGroupsSettings->get(self::GROUP_EMAIL_ADDRESS);
self::assertNotNull($groupsSettings, 'Expecting group settings to exist');
self::assertTrue(
$groupsSettings->getEmail() === self::GROUP_EMAIL_ADDRESS,
self::assertSame(
$groupsSettings->getEmail(),
self::GROUP_EMAIL_ADDRESS,
sprintf(
'Was expecting the groupsSettings.get method to return a match for the group: %s',
json_encode($groupsSettings, JSON_PRETTY_PRINT)
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "silinternational/google-api-php-client-mock",
"version": "2.15.2",
"version": "2.15.3",
"description": "Attempting to create an intelligent mock of the Google API PHP Client for unit and functional testing.",
"type": "library",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.