Skip to content

Commit

Permalink
Match secure port numbers (#124)
Browse files Browse the repository at this point in the history
Motivation
----------
Couchbase Capella uses port 18091 to represent index nodes, but we
normalize to port 8091 to compare the node list if no port is
specified.

Modifications
-------------
When connecting via the "couchbases" secure protocol, assume that index
nodes use 18091 when normalizing.
  • Loading branch information
brantburnett committed Dec 21, 2023
1 parent dc642e3 commit aa07af1
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 54 deletions.
2 changes: 1 addition & 1 deletion packages/couchbase-index-manager/app/connection-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class ConnectionManager {

this.bucket = this.cluster.bucket(this.connectionInfo.bucketName);

return new IndexManager(this.bucket, this.cluster);
return new IndexManager(this.bucket, this.cluster, this.connectionInfo.cluster.startsWith("couchbases://"));
}

/**
Expand Down
140 changes: 102 additions & 38 deletions packages/couchbase-index-manager/app/definition/index-definition.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ describe('getMutation partition change', function() {
nodes: ['a:8091'],
}),
],
isSecure: false,
})];

expect(mutations).toHaveLength(0);
Expand All @@ -538,6 +539,7 @@ describe('getMutation partition change', function() {
nodes: ['a:8091'],
},
].map(fakeIndex),
isSecure: false,
})];

expect(mutations).toHaveLength(0);
Expand All @@ -562,6 +564,7 @@ describe('getMutation partition change', function() {
nodes: ['a:8091'],
},
].map(fakeIndex),
isSecure: false,
})];

expect(mutations).toHaveLength(0);
Expand All @@ -585,6 +588,7 @@ describe('getMutation partition change', function() {
nodes: ['a:8091'],
},
].map(fakeIndex),
isSecure: false,
})];

expect(mutations).toHaveLength(1);
Expand All @@ -611,6 +615,7 @@ describe('getMutation partition change', function() {
nodes: ['a:8091'],
},
].map(fakeIndex),
isSecure: false,
})];

expect(mutations).toHaveLength(1);
Expand All @@ -632,6 +637,7 @@ describe('getMutation partition change', function() {
nodes: ['a:8091'],
},
].map(fakeIndex),
isSecure: false,
})];

expect(mutations).toHaveLength(1);
Expand All @@ -655,6 +661,7 @@ describe('getMutation partition change', function() {
nodes: ['a:8091'],
},
].map(fakeIndex),
isSecure: false,
})];

expect(mutations).toHaveLength(1);
Expand Down Expand Up @@ -684,6 +691,7 @@ describe('getMutation manual replica node changes', function() {
nodes: ['c:8091'],
},
].map(fakeIndex),
isSecure: false,
})];

expect(mutations).toHaveLength(1);
Expand Down Expand Up @@ -716,6 +724,7 @@ describe('getMutation manual replica node changes', function() {
nodes: ['a:8091'],
},
].map(fakeIndex),
isSecure: false,
})];

expect(mutations).toHaveLength(0);
Expand All @@ -737,6 +746,7 @@ describe('getMutation manual replica node changes', function() {
nodes: ['d:8091'],
},
].map(fakeIndex),
isSecure: false,
})];

expect(mutations).toHaveLength(3);
Expand Down Expand Up @@ -776,6 +786,7 @@ describe('getMutation automatic replica node changes', function() {
num_replica: 1,
},
].map(fakeIndex),
isSecure: false,
clusterVersion: {
major: 5,
minor: 5,
Expand Down Expand Up @@ -806,6 +817,7 @@ describe('getMutation automatic replica node changes', function() {
num_replica: 1,
},
].map(fakeIndex),
isSecure: false,
clusterVersion: {
major: 5,
minor: 5,
Expand All @@ -831,6 +843,7 @@ describe('getMutation automatic replica node changes', function() {
num_replica: 1,
},
].map(fakeIndex),
isSecure: false,
clusterVersion: {
major: 5,
minor: 5,
Expand Down Expand Up @@ -862,6 +875,7 @@ describe('getMutation automatic replica node changes', function() {
num_replica: 0,
},
].map(fakeIndex),
isSecure: false,
clusterVersion: {
major: 5,
minor: 5,
Expand Down Expand Up @@ -893,6 +907,7 @@ describe('getMutation automatic replica node changes', function() {
num_replica: 1,
},
].map(fakeIndex),
isSecure: false,
clusterVersion: {
major: 6,
minor: 5,
Expand Down Expand Up @@ -924,6 +939,7 @@ describe('getMutation automatic replica node changes', function() {
num_replica: 0,
},
].map(fakeIndex),
isSecure: false,
clusterVersion: {
major: 6,
minor: 5,
Expand Down Expand Up @@ -959,6 +975,7 @@ describe('getMutation automatic replica node changes', function() {
partition: 'HASH(`type`)',
},
].map(fakeIndex),
isSecure: false,
clusterVersion: {
major: 5,
minor: 5,
Expand Down Expand Up @@ -990,6 +1007,7 @@ describe('getMutation automatic replica node changes', function() {
num_replica: 1,
},
].map(fakeIndex),
isSecure: false,
clusterVersion: {
major: 5,
minor: 5,
Expand Down Expand Up @@ -1021,6 +1039,7 @@ describe('getMutation automatic replica node changes', function() {
num_replica: 1,
},
].map(fakeIndex),
isSecure: false,
clusterVersion: {
major: 6,
minor: 5,
Expand Down Expand Up @@ -1052,7 +1071,8 @@ describe('getMutation scope/collection', function() {
index_key: ['`key`'],
nodes: ['a:8091']
},
].map(fakeIndex)
].map(fakeIndex),
isSecure: false,
})];

expect(mutations).toHaveLength(0);
Expand All @@ -1074,7 +1094,8 @@ describe('getMutation scope/collection', function() {
index_key: ['`key`'],
nodes: ['a:8091']
},
].map(fakeIndex)
].map(fakeIndex),
isSecure: false,
})];

expect(mutations).toHaveLength(1);
Expand All @@ -1091,7 +1112,10 @@ describe('normalizeNodeList', function() {
nodes: ['b', 'c', 'a'],
});

def.normalizeNodeList([]);
def.normalizeNodeList({
currentIndexes: [],
isSecure: false,
});

expect(def.nodes)
.toStrictEqual(['a:8091', 'b:8091', 'c:8091']);
Expand All @@ -1104,20 +1128,42 @@ describe('normalizeNodeList', function() {
nodes: ['a', 'b', 'c'],
});

def.normalizeNodeList([]);
def.normalizeNodeList({
currentIndexes: [],
isSecure: false,
});

expect(def.nodes)
.toStrictEqual(['a:8091', 'b:8091', 'c:8091']);
});

it('adds secure port numbers', function() {
const def = new IndexDefinition({
name: 'test',
index_key: 'key',
nodes: ['a', 'b', 'c'],
});

def.normalizeNodeList({
currentIndexes: [],
isSecure: true,
});

expect(def.nodes)
.toStrictEqual(['a:18091', 'b:18091', 'c:18091']);
});

it('ignores defined port numbers', function() {
const def = new IndexDefinition({
name: 'test',
index_key: 'key',
nodes: ['a:18091', 'b', 'c'],
});

def.normalizeNodeList([]);
def.normalizeNodeList({
currentIndexes: [],
isSecure: false,
});

expect(def.nodes)
.toStrictEqual(['a:18091', 'b:8091', 'c:8091']);
Expand All @@ -1133,7 +1179,10 @@ describe('normalizeNodeList', function() {
nodes: ['b', 'c', 'a'],
});

def.normalizeNodeList([]);
def.normalizeNodeList({
currentIndexes: [],
isSecure: false,
});

expect(def.nodes)
.toStrictEqual(['a:8091', 'b:8091', 'c:8091']);
Expand All @@ -1147,7 +1196,10 @@ describe('normalizeNodeList', function() {
nodes: ['a', 'b', 'c'],
});

def.normalizeNodeList([]);
def.normalizeNodeList({
currentIndexes: [],
isSecure: false,
});

expect(def.nodes)
.toStrictEqual(['a:8091', 'b:8091', 'c:8091']);
Expand All @@ -1161,7 +1213,10 @@ describe('normalizeNodeList', function() {
nodes: ['a:18091', 'b', 'c'],
});

def.normalizeNodeList([]);
def.normalizeNodeList({
currentIndexes: [],
isSecure: false,
});

expect(def.nodes)
.toStrictEqual(['a:18091', 'b:8091', 'c:8091']);
Expand All @@ -1175,20 +1230,23 @@ describe('normalizeNodeList', function() {
nodes: ['a', 'b', 'c'],
});

def.normalizeNodeList([
{
name: 'test',
nodes: ['b:8091'],
},
{
name: 'test_replica1',
nodes: ['c:8091'],
},
{
name: 'test_replica2',
nodes: ['a:8091'],
},
].map(fakeIndex));
def.normalizeNodeList({
currentIndexes: [
{
name: 'test',
nodes: ['b:8091'],
},
{
name: 'test_replica1',
nodes: ['c:8091'],
},
{
name: 'test_replica2',
nodes: ['a:8091'],
},
].map(fakeIndex),
isSecure: false,
});

expect(def.nodes)
.toStrictEqual(['b:8091', 'c:8091', 'a:8091']);
Expand All @@ -1202,12 +1260,15 @@ describe('normalizeNodeList', function() {
nodes: ['a', 'b', 'c'],
});

def.normalizeNodeList([
{
name: 'test',
nodes: ['b:8091'],
},
].map(fakeIndex));
def.normalizeNodeList({
currentIndexes: [
{
name: 'test',
nodes: ['b:8091'],
},
].map(fakeIndex),
isSecure: false,
});

expect(def.nodes)
.toStrictEqual(['b:8091', 'a:8091', 'c:8091']);
Expand All @@ -1221,16 +1282,19 @@ describe('normalizeNodeList', function() {
nodes: ['a', 'b', 'c'],
});

def.normalizeNodeList([
{
name: 'test',
nodes: ['b:8091'],
},
{
name: 'test_replica2',
nodes: ['a:8091'],
},
].map(fakeIndex));
def.normalizeNodeList({
currentIndexes: [
{
name: 'test',
nodes: ['b:8091'],
},
{
name: 'test_replica2',
nodes: ['a:8091'],
},
].map(fakeIndex),
isSecure: false,
});

expect(def.nodes)
.toStrictEqual(['b:8091', 'c:8091', 'a:8091']);
Expand Down
Loading

0 comments on commit aa07af1

Please sign in to comment.