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

Fix for NullPointerException in Grant #304

Merged
merged 1 commit into from
Nov 5, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,14 @@ public static PNAccessManagerGrantResult from(com.pubnub.api.models.consumer.acc
private static Map<String, Map<String, PNAccessManagerKeyData>> from(Map<String, Map<String, com.pubnub.api.models.consumer.access_manager.PNAccessManagerKeyData>> data) {
Map<String, Map<String, PNAccessManagerKeyData>> newMap = new HashMap<>(data.size());
for (Map.Entry<String, Map<String, com.pubnub.api.models.consumer.access_manager.PNAccessManagerKeyData>> stringMapEntry : data.entrySet()) {
if (stringMapEntry.getValue() == null) {
continue;
}
Map<String, PNAccessManagerKeyData> innerMap = new HashMap<>(stringMapEntry.getValue().size());
for (Map.Entry<String, com.pubnub.api.models.consumer.access_manager.PNAccessManagerKeyData> innerEntry : stringMapEntry.getValue().entrySet()) {
if (innerEntry.getValue() == null) {
continue;
}
innerMap.put(innerEntry.getKey(), PNAccessManagerKeyData.from(innerEntry.getValue()));
}
newMap.put(stringMapEntry.getKey(), innerMap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.gson.annotations.SerializedName;
import lombok.Builder;
import lombok.Data;
import org.jetbrains.annotations.NotNull;

@Data
@Builder(toBuilder = true)
Expand All @@ -29,7 +30,8 @@ public class PNAccessManagerKeyData {
@SerializedName("j")
private boolean joinEnabled;

static PNAccessManagerKeyData from(com.pubnub.api.models.consumer.access_manager.PNAccessManagerKeyData data) {
@NotNull
static PNAccessManagerKeyData from(@NotNull com.pubnub.api.models.consumer.access_manager.PNAccessManagerKeyData data) {
return PNAccessManagerKeyData.builder()
.readEnabled(data.getReadEnabled())
.writeEnabled(data.getWriteEnabled())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,23 @@
import com.pubnub.api.java.models.consumer.access_manager.PNAccessManagerKeyData;
import org.junit.Test;

import java.util.Arrays;
import java.util.Collections;

import static org.junit.Assert.assertEquals;

public class GrantIT extends BaseIntegrationTest {

@Test
public void grantWithoutAuthKeyDoesntCrash() throws PubNubException {
getServer().grant().channels(Arrays.asList("abc")).write(true).read(false).ttl(0).sync();
}

@Test
public void grantAllForUUID() throws PubNubException {
String uuid = "uuid123";
String authKey = "authKey123";
int ttl = 120;

PNAccessManagerGrantResult expectedResult = PNAccessManagerGrantResult.builder()
.channelGroups(Collections.emptyMap())
.channels(Collections.emptyMap())
Expand All @@ -35,7 +40,7 @@ public void grantAllForUUID() throws PubNubException {
.build())))
.build();

PNAccessManagerGrantResult result = getServer()
PNAccessManagerGrantResult result2 = getServer()
.grant()
.uuids(Collections.singletonList(uuid))
.authKeys(Collections.singletonList(authKey))
Expand All @@ -44,7 +49,6 @@ public void grantAllForUUID() throws PubNubException {
.update(true)
.delete(true)
.sync();
System.out.println(result);
assertEquals(expectedResult, result);
assertEquals(expectedResult, result2);
}
}
Loading