Attempting to create an intelligent mock of the Google API PHP Client for unit and functional testing

Overview

google-api-php-client-mock

Travis-CI Build Status

A small scale intelligent mock of the Google API PHP Client for unit and functional testing.

Overview

This is intended to mock a portion of the Google APIs related to G Suite accounts, particularly calls relating to users and users' aliases.

Directory

Properties of a Google Service Directory (GSD) include...

  1. $users, which gets set to a GSD Users_Resource
  2. $users_aliases, which gets set to a GSD UsersAliases_Resource
  3. $asps, which gets set to a GSD Asps_Resource
  4. $tokens, which gets set to a GSD Tokens_Resource

Users_Resource

A Users_Resource has various methods for managing Google Apps users. Three of these that are implemented by this mock are ...

  1. get()
  2. insert()
  3. update()
  4. listUsers()

UsersAliases_Resource

A UsersAliases_Resource has various methods for managing Google Apps users aliases. The ones implemented by this mock are ...

  1. delete()
  2. insert()
  3. listUsersAliases()

Asps_Resource

An Asps_Resource is for managing a user's App Specific Passwords (ASPs). This mock implements...

  1. listAsps()

Tokens_Resource

A Tokens_Resource is for managing a user's OAuth access tokens. This mock implements...

  1. listTokens()

Gmail

Properties of the Gmail API object include...

  1. $users_settings
  2. $users_settings_delegates
  3. $users_settings_forwardingAddresses

UsersSettings

Methods on the UsersSettings resource that this mock implements include...

  1. updateImap()
  2. updatePop()

UsersSettingsDelegates

Methods on the UsersSettingsDelegates resource that this mock implements include...

  1. create()
  2. delete()
  3. get()
  4. listUsersSettingsDelegates()

UsersSettingsForwardingAddresses

Methods on the UsersSettingsForwardingAddresses resource that this mock implements include...

  1. listUsersSettingsForwardingAddresses()

Unit Testing

If you are able to run docker natively, then:

  • make it-now

If not, then use vagrant up:

  • vagrant up
  • vagrant ssh
  • cd /var/lib/GA_mock
  • make vagrantTest

Data Persistence

In order to keep data available for use by this mock, it makes use of a Sqlite database file. The default path and name of this file are ... SilMock/DataStore/Sqlite/Google_Service_Data.db. To override this, the constructors for the UsersResource and UsersAliasesResource class accept an optional string parameter.

The database is accessed/managed by SilMock/DataStore/Sqlite/SqliteUtils.php. It has one table with four columns ...

  1. id = INTEGER PRIMARY KEY,
  2. type = TEXT, e.g. "directory",
  3. class = TEXT, e.g. "user" or "users_alias",
  4. data = TEXT

The data field contains json with key-value pairs related to the properties of the GSD objects. The data is prepared by using the php json_encode function.

Test Fixtures

There is a class to assist with dealing with data for unit tests ... SilMock\Google\Service\GoogleFixtures.php. Its constructor accepts an optional parameter for the path and name of the Sqlite database file. It has two methods ...

  1. addFixtures($fixtures), expecting an array of 3-element arrays (type, class, data).
  2. removeAllFixtures()

Unit Tests for the Mock Itself

The SilMock/tests folder includes phpunit tests for the three main portions of this mock (Directory, GoogleFixtures, SqliteUtils). These should help provide examples of how to use the mock.

Examples

Switching between the Mock and the Real GSD

public static function useRealGoogle() {
    return  ( ! isset (\Yii::app()->params['use_real_google']) ||
              \Yii::app()->params['use_real_google']);
}

public static function getGoogleServiceDirectory($client) {
    if (self::useRealGoogle()) {
        return new Google_Service_Directory($client);
    }
    $db_path = null;
    if (isset(\Yii::app()->params['googleMockDbPath'])) {
        $db_path = \Yii::app()->params['googleMockDbPath'];
    }
    return new SilMock\Google\Service\Directory($client, $db_path);
}

Managing a User

$dir = self::getGoogleServiceDirectory($client);
$google_user = new Google_Service_Directory_User();
$google_user = $dir->users->insert($google_user);
$google_user = $dir->users->get($usersEmail);

$google_user->suspended = true;
$google_user->suspensionReason = 'ADMIN';
$account = $dir->users->update($users_email, $google_user);

Managing a User's Aliases

$dir = self::getGoogleServiceDirectory($client);
$google_alias = new Google_Service_Directory_Alias();
$google_alias->setAlias($alias);
$alias = $dir->users_aliases->insert($users_email, $google_alias);

$aliases = $dir->users_aliases->listUsersAliases($users_email);
$alias = $dir->users_aliases->delete($users_email, $alias);
Comments
  • CVE-2020-11023 (Medium) detected in phpunit/php-code-coverage-7.0.10, jquery-3.4.1.min.js

    CVE-2020-11023 (Medium) detected in phpunit/php-code-coverage-7.0.10, jquery-3.4.1.min.js

    CVE-2020-11023 - Medium Severity Vulnerability

    Vulnerable Libraries - phpunit/php-code-coverage-7.0.10, jquery-3.4.1.min.js

    phpunit/php-code-coverage-7.0.10

    Library that provides collection, processing, and rendering functionality for PHP code coverage information.

    Library home page: https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/f1884187926fbb755a9aaf0b3836ad3165b478bf

    Dependency Hierarchy:

    • phpunit/phpunit-8.5.8 (Root Library)
      • :x: phpunit/php-code-coverage-7.0.10 (Vulnerable Library)
    jquery-3.4.1.min.js

    JavaScript library for DOM operations

    Library home page: https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js

    Path to vulnerable library: /google-api-php-client-mock/vendor/phpunit/php-code-coverage/src/Report/Html/Renderer/Template/js/jquery.min.js

    Dependency Hierarchy:

    • :x: jquery-3.4.1.min.js (Vulnerable Library)

    Found in HEAD commit: 906299b23fe4f384216ab645d4a32d4cf73845c6

    Vulnerability Details

    In jQuery versions greater than or equal to 1.0.3 and before 3.5.0, passing HTML containing

    Publish Date: 2020-04-29

    URL: CVE-2020-11023

    CVSS 3 Score Details (6.1)

    Base Score Metrics:

    • Exploitability Metrics:
      • Attack Vector: Network
      • Attack Complexity: Low
      • Privileges Required: None
      • User Interaction: Required
      • Scope: Changed
    • Impact Metrics:
      • Confidentiality Impact: Low
      • Integrity Impact: Low
      • Availability Impact: None

    For more information on CVSS3 Scores, click here.

    Suggested Fix

    Type: Upgrade version

    Origin: https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-11023

    Release Date: 2020-04-29

    Fix Resolution: jquery - 3.5.0


    Step up your Open Source Security Game with WhiteSource here

    security vulnerability 
    opened by mend-bolt-for-github[bot] 1
  • Release 0.7.2

    Release 0.7.2

    Release 0.7.2

    Add

    • isEnrolledIn2Sv and isEnforcedIn2Sv to tests

    Fixed

    • PSR-2 issues
    • PHPDoc in multiple files.
    • missing ext-pdo reference in composer.json

    Security

    • Updated composer.lock
    opened by mtompset 1
  • CVE-2020-11022 (Medium) detected in phpunit/php-code-coverage-7.0.10, jquery-3.4.1.min.js

    CVE-2020-11022 (Medium) detected in phpunit/php-code-coverage-7.0.10, jquery-3.4.1.min.js

    CVE-2020-11022 - Medium Severity Vulnerability

    Vulnerable Libraries - phpunit/php-code-coverage-7.0.10, jquery-3.4.1.min.js

    phpunit/php-code-coverage-7.0.10

    Library that provides collection, processing, and rendering functionality for PHP code coverage information.

    Library home page: https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/f1884187926fbb755a9aaf0b3836ad3165b478bf

    Dependency Hierarchy:

    • phpunit/phpunit-8.5.2 (Root Library)
      • :x: phpunit/php-code-coverage-7.0.10 (Vulnerable Library)
    jquery-3.4.1.min.js

    JavaScript library for DOM operations

    Library home page: https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js

    Path to vulnerable library: /google-api-php-client-mock/vendor/phpunit/php-code-coverage/src/Report/Html/Renderer/Template/js/jquery.min.js

    Dependency Hierarchy:

    • :x: jquery-3.4.1.min.js (Vulnerable Library)

    Found in HEAD commit: bd8888bbf905823ce1c91e2dbaf244fb3d31d7d6

    Vulnerability Details

    In jQuery versions greater than or equal to 1.2 and before 3.5.0, passing HTML from untrusted sources - even after sanitizing it - to one of jQuery's DOM manipulation methods (i.e. .html(), .append(), and others) may execute untrusted code. This problem is patched in jQuery 3.5.0.

    Publish Date: 2020-04-29

    URL: CVE-2020-11022

    CVSS 3 Score Details (6.1)

    Base Score Metrics:

    • Exploitability Metrics:
      • Attack Vector: Network
      • Attack Complexity: Low
      • Privileges Required: None
      • User Interaction: Required
      • Scope: Changed
    • Impact Metrics:
      • Confidentiality Impact: Low
      • Integrity Impact: Low
      • Availability Impact: None

    For more information on CVSS3 Scores, click here.

    Suggested Fix

    Type: Upgrade version

    Origin: https://blog.jquery.com/2020/04/10/jquery-3-5-0-released/

    Release Date: 2020-04-29

    Fix Resolution: jQuery - 3.5.0


    Step up your Open Source Security Game with WhiteSource here

    security vulnerability 
    opened by mend-bolt-for-github[bot] 1
  • Dockerize

    Dockerize

    • Deleted unused file .coveralls.yml
    • Reworked dockerfile, updated README.md
    • Added docker-compose.yml file bases on PHP 7.2
    • Install composer in /usr/bin/composer (usr/local/bin/composer is more proper, but doesn't work)
    • change Makefile to be more as expected
    • composer lock update
    opened by mtompset 1
  • Feature/dockerize

    Feature/dockerize

    • Added docker-compose.yml and a Dockerfile to build a docker image and container.
    • Update README.md so people know how to test
    • Added Makefile commands
    • Added script to do composer installing/updating.
    opened by mtompset 1
  • Release 0.5.0 - mock listUsers

    Release 0.5.0 - mock listUsers

    Added:

    • Google Service Directory UsersResource API endpoint mocks:
      • google_service_directory->users->listUsers([
        • 'domain' => $domain,
        • 'maxResults' => $max_results,
        • 'query' => $query
      • ])
    opened by mtompset 1
  • Add delete() to Google mock token object

    Add delete() to Google mock token object

    Added

    • delete() for Google_Service_Directory_Token mock

    Fixed

    • Properly pass the mock database file name
    • Code quality improvements including some refactoring, PSR12, and PHPDoc clean up
    opened by mtompset 0
  • Feature/cleanup and delete token

    Feature/cleanup and delete token

    Added

    • delete() for Google_Service_Directory_Token mock
    • A new base class DbClass for various Google service mocks to extend

    Changed

    • PSR12 clean up of several pieces of code
    • Refactoring to extend a base DbClass

    Fix

    • Properly pass the mock database file name
    • Minor static analysis issues and PHPDoc
    opened by mtompset 0
  • Release 1.0.2

    Release 1.0.2

    Changed

    • Changed tag from a commit-based reference to a version tag (that refers to the same commit)

    Removed

    • Removed deprecated sqlite dependency in Docker image used for tests and composer updates
    opened by forevermatt 0
  • Feature/switch to tag

    Feature/switch to tag

    Changed

    • Changed tag from a commit-based reference to a version tag.

    Removed

    • Removed deprecated sqlite dependency

    Updated

    • Updated composer.lock file
    opened by mtompset 0
  • Feature/move to php7.3

    Feature/move to php7.3

    Modify Dockerfile to use official PHP 7.3 apache buster image Optimize Dockerfile Modify composer.json to use PHP7.3 and PHPUnit 9.5.4 at least Rebuild composer.lock

    security fix 
    opened by mtompset 0
Releases(1.4.0)
  • 1.4.0(Jul 12, 2022)

  • 1.3.1(Jul 12, 2022)

    Added

    • Default agreedToTerms to false

    Fixed

    • Corrected to ISO-8601 format for creationTime and lastLoginTime
    • Corrected published against main not develop
    Source code(tar.gz)
    Source code(zip)
  • 1.3.0(Jul 12, 2022)

  • 1.2.1(May 16, 2022)

  • 1.2.0(Mar 21, 2022)

    Added

    • delete() for Google_Service_Directory_Token mock

    Fixed

    • Properly pass the mock database file name
    • Code quality improvements including some refactoring, PSR12, and PHPDoc clean up
    Source code(tar.gz)
    Source code(zip)
  • 1.1.0(Mar 16, 2022)

    Add

    • Skeleton delete() to UserSettingsForwardingAddresses mock
    • Skeleton tests for listUserSettingsForwardingAddresses() and delete()

    Change

    • Revise make clean to remove only stopped containers, and not prune networks, images, and volumes too
    Source code(tar.gz)
    Source code(zip)
  • 1.0.2(Jan 5, 2022)

    Changed

    • Changed tag from a commit-based reference to a version tag (that refers to the same commit)

    Removed

    • Removed deprecated sqlite dependency in Docker image used for tests and composer updates
    Source code(tar.gz)
    Source code(zip)
  • 1.0.1(Jun 10, 2021)

  • 1.0.0(Mar 24, 2021)

  • 0.9.0(Jan 11, 2021)

  • 0.8.1(Aug 24, 2020)

  • 0.8.0(Aug 7, 2020)

  • 0.7.1(Apr 8, 2020)

  • 0.7.0(Apr 6, 2020)

    Fixed:

    • Add test for listUsersSettingsDelegates()
    • Fix listUsersSettingsDelegates() method to return delegates that the mock has been given

    Changed:

    • Revise make clean to clean up Docker images, not Composer dependencies
    • Rename make test (for testing via Vagrant) to make vagrantTest
    • Rename make phpunit (for testing via Docker) to make test
    Source code(tar.gz)
    Source code(zip)
  • 0.6.1(Mar 24, 2020)

  • 0.6.0(Mar 17, 2020)

  • 0.5.0(Aug 30, 2019)

    Added:

    • Google Service Directory UsersResource API endpoint mocks:
      • google_service_directory->users->listUsers([
        • 'domain' => $domain,
        • 'maxResults' => $max_results,
        • 'query' => $query
      • ])
    Source code(tar.gz)
    Source code(zip)
  • 0.3.2(Mar 27, 2019)

    Fixed:

    • Providing an alias to get a user now returns the user (if one exists)

    Note: This was originally intended to be released as version 0.3.1, but I accidentally tagged the wrong commit as 0.3.1, so this is now 0.3.2.

    Source code(tar.gz)
    Source code(zip)
  • 0.3.0(Mar 19, 2019)

Owner
SIL International
SIL International
OpenAI API Client is a component-oriented, extensible client library for the OpenAI API. It's designed to be faster and more memory efficient than traditional PHP libraries.

OpenAI API Client in PHP (community-maintained) This library is a component-oriented, extensible client library for the OpenAI API. It's designed to b

Mounir R'Quiba 6 Jun 14, 2023
Google PHP API Client Services

Google PHP API Client Services

Google APIs 1.1k Dec 22, 2022
PHP JSON-RPC 2.0 Server/Client Implementation with Automatic Client Class Generation via SMD

PHP JSON-RPC 2.0 Server/Client Implementation with Automatic Client Class Generation via SMD

Sergey Bykov 63 Feb 14, 2022
Nexmo REST API client for PHP. API support for SMS, Voice, Text-to-Speech, Numbers, Verify (2FA) and more.

Client Library for PHP Support Notice This library and it's associated packages, nexmo/client and nexmo/client-core have transitioned into a "Maintena

Nexmo 75 Sep 23, 2022
DigitalOcean API v2 client for Symfony and API Platform

DigitalOcean Bundle for Symfony and API Platform DunglasDigitalOceanBundle allows using the DigitalOcean API from your Symfony and API Platform projec

Kévin Dunglas 25 Jul 27, 2022
API client for ThePay - payment gate API

This is the official highly compatible public package of The Pay SDK which interacts with The Pay's REST API. To get started see examples below.

ThePay.cz s.r.o. 3 Oct 27, 2022
Code Quiz MonoRepo (API, API Client, App)

Code Quiz Welcome to the Code Quiz Open Source project from How To Code Well. This is an Open Source project that includes an API and an App for the d

How To Code Well 2 Nov 20, 2022
PHP package to manage google-api interactions

Google-api-client PHP package to manage google-api interactions Supports: Google Drive API Google Spreadsheet API Installation composer require obrio-

OBRIO 3 Apr 28, 2022
🌐 Free Google Translate API PHP Package. Translates totally free of charge.

Google Translate PHP Free Google Translate API PHP Package. Translates totally free of charge. Installation Basic Usage Advanced Usage Language Detect

Levan Velijanashvili 1.5k Dec 31, 2022
Google Drive Api Wrapper by PHP

GoogleDrive Api Wrapper usage at first you need to create oauth client on google cloud platform. so go to the your google console dashboard and create

Arash Abedi 2 Mar 24, 2022
Google Translator Api Wrapper For Php Developers.

Google Translator Api Wrapper For Php Developers.

Roldex Stark 2 Oct 12, 2022
An elegant wrapper around Google Vision API

STILL UNDER DEVELOPMENT - DO NOT USE IN PRODUCTION Requires PHP 8.0+ For feedback, please contact me. This package provides an elegant wrapper around

Ahmad Mayahi 24 Nov 20, 2022
Simple Google Tts Api Class

Simple Google Tts Api Class

Ömer Faruk Demirel 2 Dec 2, 2022
A simple PHP GitHub API client, Object Oriented, tested and documented.

PHP GitHub API A simple Object Oriented wrapper for GitHub API, written with PHP. Uses GitHub API v3 & supports GitHub API v4. The object API (v3) is

KNP Labs 2k Jan 7, 2023
⚡️ Web3 PHP is a supercharged PHP API client that allows you to interact with a generic Ethereum RPC.

Web3 PHP is a supercharged PHP API client that allows you to interact with a generic Ethereum RPC. This project is a work-in-progress. Code and docume

Web3 PHP 665 Dec 23, 2022
A simple Object Oriented PHP Client for Termii SMS API

Termii Client A simple Object Oriented PHP Client for Termii SMS API. Uses Termii API. Requirements PHP >= 7.2 Guzzlehttp ~6|~7 Installation Via Compo

Ilesanmi Olawale Adedotun 5 Feb 24, 2022
Xendit REST API Client for PHP - Card, Virtual Account, Invoice, Disbursement, Recurring Payments, Payout, EWallet, Balance, Retail Outlets Services

Xendit REST API Client for PHP - Card, Virtual Account, Invoice, Disbursement, Recurring Payments, Payout, EWallet, Balance, Retail Outlets Services

Xendit 96 Jan 6, 2023
php 8 client for the lemon.markets api

lemon.markets php client This repository contains a php 8+ compatible client for the https://lemon.markets API. The documentation of the API can be fo

Daniel Freudenberger 4 Nov 17, 2022
PHP client for Microsoft Azure Face API.

Microsoft Azure Face API PHP client A PHP library that utilizes Azure Face REST API. Requirements PHP >= 7.4 Installation composer require darmen/php-

Darmen Amanbayev 6 Sep 14, 2022