Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PAM tests for chat operations #24

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from
Draft

Conversation

KGronek-Pubnub
Copy link
Contributor

No description provided.

@KGronek-Pubnub
Copy link
Contributor Author

PR not ready yet, I need to adjust cmake and move tests from example.

Comment on lines +61 to +63
set(OPENSSL_ROOT_DIR "C:/Program Files/Epic Games/UE_5.4/Engine/Source/ThirdParty/OpenSSL/1.1.1t")
set(CUSTOM_OPENSSL_LIB_DIR "lib/Win64/VS2015/Release")
set(CUSTOM_OPENSSL_INCLUDE_DIR "include/Win64/VS2015")
Copy link
Contributor

Choose a reason for hiding this comment

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

We cannot push it into the repository.
It will break for me and @jakub-grzesiowski .

@@ -1,3 +1,1591 @@
#include "pubnub_chat/message.hpp"
Copy link
Contributor

Choose a reason for hiding this comment

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

it shouldn't be also a part of the PR ;d

Comment on lines +74 to +75
//Make sure token data is provided in correct form. There must be the same amount of object and permissions or just one permission,
//then one permission is used for every object
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we start using formating - because reading of the PRs start to become much harder and harder :/

I provided the one .clang-format as a proposal.
We can change it to any format we want but we should stick with one formatting within this Repo.

Comment on lines +77 to +206
if(permission_object_struct.user_patterns.size() != permission_object_struct.user_pattern_permissions.size() && permission_object_struct.user_pattern_permissions.size() != 1)
{
throw std::runtime_error("Grant Token Structure To JsonString - Provide the same amount of user_pattern_permissions and usersPatterns (or only 1 user_pattern_permissions).");
return "";
}

Json permission_object_json;

//Create Json objects with channels, groups, users permissions and their patterns
Json channels_json_object = add_channel_permissions_to_json(permission_object_struct.channels, permission_object_struct.channel_permissions);
Json channel_groups_json_object = add_channel_group_permissions_to_json(permission_object_struct.channel_groups, permission_object_struct.channel_group_permissions);
Json users_json_object = add_user_permissions_to_json(permission_object_struct.users, permission_object_struct.user_permissions);
Json channel_patterns_json_object = add_channel_permissions_to_json(permission_object_struct.channel_patterns, permission_object_struct.channel_pattern_permissions);
Json channel_group_patterns_json_object = add_channel_group_permissions_to_json(permission_object_struct.channel_group_patterns, permission_object_struct.channel_group_pattern_permissions);
Json user_patterns_json_object= add_user_permissions_to_json(permission_object_struct.user_patterns, permission_object_struct.user_pattern_permissions);

//Add resources fields
Json resources_json_object;
if(permission_object_struct.channels.size() > 0)
{
resources_json_object.insert_or_update("channels", channels_json_object);
}
if(permission_object_struct.channel_groups.size() > 0)
{
resources_json_object.insert_or_update("groups", channel_groups_json_object);
}
if(permission_object_struct.users.size() > 0)
{
resources_json_object.insert_or_update("uuids", users_json_object);
}

//Add patterns fields
Json patterns_json_object;
if(permission_object_struct.channel_patterns.size() > 0)
{
patterns_json_object.insert_or_update("channels", channel_patterns_json_object);
}
if(permission_object_struct.channel_group_patterns.size() > 0)
{
patterns_json_object.insert_or_update("groups", channel_group_patterns_json_object);
}
if(permission_object_struct.user_patterns.size() > 0)
{
patterns_json_object.insert_or_update("uuids", user_patterns_json_object);
}

Json permission_object_struct_json_object;
if(!resources_json_object.is_null())
{
permission_object_struct_json_object.insert_or_update("resources", resources_json_object);
}
if(!patterns_json_object.is_null())
{
permission_object_struct_json_object.insert_or_update("patterns", patterns_json_object);
}

Json permissions_json_object;
permissions_json_object.insert_or_update("ttl", permission_object_struct.ttl_minutes);
permissions_json_object.insert_or_update("authorized_uuid", permission_object_struct.authorized_user);
permissions_json_object.insert_or_update("permissions", permission_object_struct_json_object);

//Convert created Json object to string
return permissions_json_object.dump();
}



Json AccessManagerService::add_channel_permissions_to_json(std::vector<Pubnub::String> channels, std::vector<Pubnub::ChannelPermissions> channel_permissions) const
{
Json json_object;
bool use_one_permission = channel_permissions.size() == 1;

for(int i = 0; i < channels.size(); i++)
{
if(channels[i].empty())
{
continue;
}

//For permissions use the first index if this is the only valid index or corresponding channel index
Pubnub::ChannelPermissions current_permissions;
use_one_permission ? current_permissions = channel_permissions[0] : current_permissions = channel_permissions[i];

//Create bit mask value from all permissions
struct pam_permission ChPerm;
ChPerm.read = current_permissions.read;
ChPerm.write = current_permissions.write;
ChPerm.del = current_permissions.del;
ChPerm.get = current_permissions.get;
ChPerm.update = current_permissions.update;
ChPerm.manage = current_permissions.manage;
ChPerm.join = current_permissions.join;
ChPerm.create = false;
int perm_bit_mask = pubnub_get_grant_bit_mask_value(ChPerm);

json_object.insert_or_update(channels[i], perm_bit_mask);
}

return json_object;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you split this function into few functions - to help tracking what's going on here.
You can move the validations into the domain section to make it easier to test.

Same for creation of structs.

@KGronek-Pubnub KGronek-Pubnub marked this pull request as draft March 17, 2025 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants